Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
853 views
in Technique[技术] by (71.8m points)

android - Room migration: "no such table: room_table_modification_log"

Room 1.1.0 version.

I am getting this error on the first run after migration.

It runs well if I close the app and start it again.

ROOM: Cannot run invalidation tracker. Is the db closed?
java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
    at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:1182)
    at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:792)
    at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:518)

Caused By : SQL(query) error or missing database.
    (no such table: room_table_modification_log (code 1): , while compiling: DELETE FROM proposals WHERE hotel_id = ?)
#################################################################
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1095)
    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:660)
    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
    at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
    at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1417)
    at android.arch.persistence.db.framework.FrameworkSQLiteDatabase.compileStatement(FrameworkSQLiteDatabase.java:64)
    at android.arch.persistence.room.RoomDatabase.compileStatement(RoomDatabase.java:244)
    at android.arch.persistence.room.SharedSQLiteStatement.createNewStatement(SharedSQLiteStatement.java:65)
    at android.arch.persistence.room.SharedSQLiteStatement.getStmt(SharedSQLiteStatement.java:77)
    at android.arch.persistence.room.SharedSQLiteStatement.acquire(SharedSQLiteStatement.java:87)
    at com.hotellook.db.dao.FavoritesDao_Impl.removeProposals(FavoritesDao_Impl.java:723)

The DB initialization code looks like this (Dagger AppModule)

@Provides
@Singleton
fun provideDataBase(app: Application): AppDatabase =
  Room.databaseBuilder(app, AppDatabase::class.java, DATABASE_NAME)
      .addMigrations(MIGRATION_1_2)
      .addMigrations(MIGRATION_2_3)
      .build()

private companion object {
  const val DATABASE_NAME = "app.db"

  val MIGRATION_1_2 = object : Migration(1, 2) {
    override fun migrate(database: SupportSQLiteDatabase) {
      database.execSQL("ALTER TABLE table1 ADD COLUMN column0 TEXT;")
      database.execSQL("ALTER TABLE table2 ADD COLUMN column0 TEXT;")
    }
  }

  val MIGRATION_2_3 = object : Migration(2, 3) {
    override fun migrate(database: SupportSQLiteDatabase) {
      database.execSQL("CREATE TABLE table0 (column1 INTEGER NOT NULL, column2 TEXT NOT NULL, PRIMARY KEY(column1))")
      database.execSQL("ALTER TABLE table1 ADD COLUMN column1 TEXT;")
      database.execSQL("ALTER TABLE table1 ADD COLUMN column2 TEXT;")
      database.execSQL("ALTER TABLE table1 ADD COLUMN column3 REAL;")
      database.execSQL("ALTER TABLE table2 ADD COLUMN column1 TEXT;")
      database.execSQL("ALTER TABLE table2 ADD COLUMN column2 REAL;")
      database.execSQL("ALTER TABLE table3 ADD COLUMN column1 INTEGER DEFAULT 0;")
      database.execSQL("ALTER TABLE table3 ADD COLUMN column2 TEXT;")
    }
  } 

The app upgrades from version 2 to 3. How can I fix it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Bump up the version to 1.1.1-rc1 and this nonsensical error that stems from Google's own code will not happen anymore, I've tested the same scenario on numerous devices.

Also see my question/answer here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...