Skip to content
Advertisement

Unable to migrate android sqllite database

I have been running the onUpgrade method without issues, until this column:

    @OnUpgrade
    public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
    {        
        db.beginTransaction();
        db.execSQL("ALTER TABLE parents ADD COLUMN account_is_in_credit_for_amount TEXT DEFAULT ''");
        db.endTransaction();
    }

I have updated the database version. The above has been simplified to try and make sure that nothing else is causing this column to not be created.

Note that if I uninstall the app and reinstall the app, then it runs without issue.

How would I go about debugging this issue further?

I imagine I need to provide more information, but I’m not sure what would help. Every idea that I have had, I have tried.

The error is:

unable to resume activity
{... .SplashScreenActivity}
android.database.sqlite.SQLLiteException: no such columns: parents.account_is_in_credit_for_amount (code 1):, while selecting

Advertisement

Answer

From https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#beginTransaction():

The changes will be rolled back if any transaction is ended without being marked as clean (by calling setTransactionSuccessful). Otherwise they will be committed.

So call:

db.setTransactionSuccessful();

before:

db.endTransaction();
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement