Android Room 数据库升级报错 - attempt to re-open an already-closed object

Android Room SQLite Data migration - attempt to re-open an already-closed object
查阅文章发现Room 要求:所有整数不为空,向主键添加autoincrement,十进制数为实数,不为空。
例如:
报错代码

database.execSQL("CREATE TABLE Membership (mID INTEGER, mName TEXT, mBarcode TEXT, mType TEXT, PRIMARY KEY(mID))");

改为

database.execSQL("CREATE TABLE Membership (mID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, mName TEXT, mBarcode TEXT, mType TEXT);");

你可能感兴趣的:(Android)