Room cannot verify the data integrity

前端 未结 20 2348
一向
一向 2020-12-04 11:43

I am getting this error while running program with Room Database

Room cannot verify the data integrity. Looks like you\'ve changed schema but forgot to updat         


        
20条回答
  •  广开言路
    2020-12-04 12:32

    In order to fix the problem in kotlin:

    First

    @Database(entities = [Contact::class], version = 2)
    

    Second

    val MIGRATION_1_2 = object : Migration(1, 2) {
            override fun migrate(database: SupportSQLiteDatabase) {
                database.execSQL("ALTER TABLE Contact ADD COLUMN seller_id TEXT NOT NULL DEFAULT ''")
            }
        }
    

    Third

    private fun buildDatabase(context: Context) = Room.databaseBuilder(
                context.applicationContext,
                EpayDatabase::class.java,
                "epay"
            )
                .addMigrations(MIGRATION_1_2)
                .build()
    

    For more details, check the official documentation

提交回复
热议问题