DBFlow icon indicating copy to clipboard operation
DBFlow copied to clipboard

IllegalStateException: Cannot perform this operation because there is no current transaction

Open royorange opened this issue 4 years ago • 1 comments

DBFlow Version: 4.2.4

Bug or Feature Request: Runtime exception

Description: The lib works well, but I found some crash issue from users after a migration. The online log collected the exception, here is the stacktrace:

Caused by: java.lang.IllegalStateException: Cannot perform this operation because there is no current transaction.
	at android.database.sqlite.SQLiteSession.throwIfNoTransaction(SQLiteSession.java:937)
	at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:410)
	at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:611)
	at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:442)
	at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:332)
	at com.raizlabs.android.dbflow.structure.database.FlowSQLiteOpenHelper.getDatabase(FlowSQLiteOpenHelper.java:62)
	at com.raizlabs.android.dbflow.config.DatabaseDefinition.getWritableDatabase(DatabaseDefinition.java:257)
	at com.raizlabs.android.dbflow.sql.queriable.ModelLoader.load(ModelLoader.java:36)
	at com.raizlabs.android.dbflow.sql.queriable.ListModelLoader.load(ListModelLoader.java:25)
	at com.raizlabs.android.dbflow.sql.language.BaseModelQueriable.queryList(BaseModelQueriable.java:61)
	at com.raizlabs.android.dbflow.sql.language.Where.queryList(Where.java:236)

The migration is about change the primary key of one table, and everything works well during the test. the migration sql file is:

drop table SearchData;
create table SearchData
(
  text              TEXT,
  url               TEXT,
  updateDate        INTEGER,
  primary key(text)
);
COMMIT;

How can I fix it? Thanks

royorange avatar Mar 29 '21 03:03 royorange

It looks like something wrong in the FlowSQLiteOpenHelper.onUpgrade method?

royorange avatar Mar 29 '21 04:03 royorange