'How to resolve the duplicate column name error in Room Db migration
I added the below code for adding a column to the SithluBody
table when migration.
static final Migration MIGRATION_3_4 = new Migration(3, 4) {
@Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE SithaluBody ADD COLUMN has_thumb INTEGER NOT NULL
DEFAULT 0");
database.execSQL("ALTER TABLE SithaluBody ADD COLUMN reacts TEXT");
}
};
but I got the error ==>
Fatal Exception: android.database.sqlite.SQLiteException duplicate column name: has_thumb (code 1 SQLITE_ERROR). How can I fix it? please help me.
Solution 1:[1]
This can be one of the two problems:
You have the
has_thumb
column added.You installed an older version in your device/emulator that had that column name, and now that you are trying to do this migration, it's having a conflict.
In case of the second option, try to uninstall or clear the data of you app in the device/emulator and try to install the app again.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Daniel Beleza |