Closed pishguy closed 7 years ago
increase the database version. app version has nothing to do with database version. https://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onUpgrade(android.database.sqlite.SQLiteDatabase, int, int) is where we do new tables, migrations,etc.
ok so how can i create custom class to have migration file? dbflow has any helper to upgrade database?
i cant find any documentation about that on this library migration
Just add your table and increment the database version. Restart the app.
Mahdi, below is how I've done it. I assume a CREATE TABLE sqlite command is not needed - I haven' tried adding a completely new table yet.
@Migration(version = 3, database = AppDatabase.class)
public class MigrateTo03 extends BaseMigration {
@Override
public void migrate(@NonNull DatabaseWrapper database) {
database.execSQL("ALTER TABLE `Person` ADD COLUMN `birthState` TEXT;");
database.execSQL("ALTER TABLE `Person` ADD COLUMN `birthCountry` TEXT;");
//database.execSQL("CREATE TABLE `HealthTopic` ... etc... ;"); not needed ?
Timber.i("Upgraded Database to version 3");
}
}
I can confirm that if you add a new table and don't increase the database version, then you'll see
Caused by: android.database.sqlite.SQLiteException: no such table: ... etc
When you increase the DB version, it'll work without needing to specifically add migration code (CREATE TABLE)
when i try to have some new table on application i increase app version and i expectation to create new table, but i get error such as:
no such table: UserChannelInformation (code 1): , while compiling: INSERT INTO
UserChannelInformation
(channelId
) VALUES (?)