Crashlytics notify about an error with migration on the production version of my app.
Fatal Exception: android.database.sqlite.SQLiteException: table NotificationsRoomEntity already exists (code 1 SQLITE_ERROR): , while compiling: CREATE TABLE NotificationsRoomEntity (
id INTEGER NOT NULL,
sentDate TEXT NOT NULL,
title TEXT NOT NULL,
message TEXT NOT NULL,
type TEXT NOT NULL,
commandId INTEGER NOT NULL,
readDate TEXT,
PRIMARY KEY(id)
)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:903)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:514)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
This table is new in my app and cannot exist in the past. What circumstances are the reason for these exceptions? The migration tests are running successfully, and there was no table with this name in the previous schemas. In some sources I have seen the "CREATE TABLE IF NOT EXISTS" procedure, but can I be sure that the table will be up-to-date if it really already exists? My migration code is below.
val MIGRATION_6_7 = object : Migration(6, 7) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(
"""
CREATE TABLE NotificationsRoomEntity (
id INTEGER NOT NULL,
sentDate TEXT NOT NULL,
title TEXT NOT NULL,
message TEXT NOT NULL,
type TEXT NOT NULL,
commandId INTEGER NOT NULL,
readDate TEXT,
PRIMARY KEY(id)
)
"""
)
}
}