DBFlow
DBFlow copied to clipboard
IllegalStateException using IndexMigration
Hi Great library!
I get an java.lang.IllegalStateException: getDatabase called recursively, when I try to do an IndexMigration. The migration class looks as follows:
@Migration(version = 2, databaseName = AppDatabase.NAME)
public class Migration1 extends IndexMigration<ShoppingList> {
public Migration1() {
super("nameIdx",ShoppingList.class);
}
@Override
public void onPreMigrate() {
super.onPreMigrate();
addColumn(ShoppingList$Table.NAME);
}
}
Call stack:
java.lang.IllegalStateException: getDatabase called recursively
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalStateException: getDatabase called recursively
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:203)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at com.raizlabs.android.dbflow.config.BaseDatabaseDefinition.getWritableDatabase(BaseDatabaseDefinition.java:140)
at com.raizlabs.android.dbflow.sql.index.Index.enable(Index.java:111)
at com.raizlabs.android.dbflow.sql.migration.IndexMigration.migrate(IndexMigration.java:42)
at com.raizlabs.android.dbflow.config.FlowSQLiteOpenHelper$4.run(FlowSQLiteOpenHelper.java:420)
at com.raizlabs.android.dbflow.runtime.TransactionManager.transact(TransactionManager.java:120)
at com.raizlabs.android.dbflow.config.FlowSQLiteOpenHelper.executeMigrations(FlowSQLiteOpenHelper.java:397)
at com.raizlabs.android.dbflow.config.FlowSQLiteOpenHelper.onUpgrade(FlowSQLiteOpenHelper.java:313)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:256)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at com.raizlabs.android.dbflow.config.BaseDatabaseDefinition.getWritableDatabase(BaseDatabaseDefinition.java:140)
at com.raizlabs.android.dbflow.sql.SqlUtils.queryList(SqlUtils.java:86)
at com.raizlabs.android.dbflow.sql.language.Where.queryList(Where.java:322)
at com.raizlabs.android.dbflow.sql.language.From.queryList(From.java:134)
Without the Migrations class the code executes without any problems. As far as I can tell it happens because:
- I query the database which internally in DBFLOW calls getWritableDatabase
- FlowSQLiteOpenHelper detects the migration and getWritableDatabase gets called once more.
Best regards Christian
great find! It turns out I need to pass in the SQLiteDatabase object to the migration. Let me put this for 1.7.1!
For now override migrate() and call `database.execSql(getQuery())`` instead.
Thanks for the answer. Keep up the good work! :)