У меня есть база данных с таблицей Profile с версией 1. Теперь я хочу изменить эту таблицу и добавить текстовое поле createAt. * 1001 *
Я создал миграцию:
public static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE Profile "+ " ADD COLUMN createdAt TEXT");
}
};
Я добавил это здесь:
@Provides @Singleton public AppDatabase provideDatabase(@Named(DIConstants.APP) Context context) {
return Room.databaseBuilder(context, AppDatabase.class, "appdb")
.addMigrations(AppDatabase.MIGRATION_1_2)
.build();
}
Теперь, когда я запускаю приложение, я получаю эту ошибку:
Process: org.app.app.debug, PID: 4800
java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/user/0/org.app.rapp.debug/databases/appdb
at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1659)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)
at android.arch.persistence.db.framework.FrameworkSQLiteDatabase.execSQL(FrameworkSQLiteDatabase.java:240)
at org.app.app.data.sql.AppDatabase$1.migrate(AppDatabase.java:65)
at android.arch.persistence.room.RoomOpenHelper.onUpgrade(RoomOpenHelper.java:73)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onUpgrade(FrameworkSQLiteOpenHelper.java:118)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:256)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:93)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:54)
at android.arch.persistence.room.RoomDatabase.inTransaction(RoomDatabase.java:305)
at android.arch.persistence.room.InvalidationTracker$1.run(InvalidationTracker.java:281)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)