question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

App crashes if add new column in new version of app

See original GitHub issue

DBFlow Version: 4.1.1 Issue Kind (Bug, Question, Feature): Bug

I add new column to table cause crash

Description: I added some tables in my app with DBFlow in previous app version. Now I want to add new column to one of tables in new version of app. When I update and run the app, the app crashes. But I remove previous version and install new version, any things are ok. logcat report:

FATAL EXCEPTION: main Process: com.consoleco.console, PID: 12896 android.database.sqlite.SQLiteException: table Message has no column named link (code 1): , while compiling: INSERT OR REPLACE INTO Message(messageId,date,sender,messageTitle,messageBody,link) VALUES (?,?,?,?,?,?) at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:893) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:504) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31) at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1017) at com.raizlabs.android.dbflow.structure.database.AndroidDatabase.compileStatement(AndroidDatabase.java:56) at com.raizlabs.android.dbflow.structure.ModelAdapter.getInsertStatement(ModelAdapter.java:119) at com.raizlabs.android.dbflow.structure.ModelAdapter.getInsertStatement(ModelAdapter.java:58) at com.raizlabs.android.dbflow.sql.saveable.ModelSaver.save(ModelSaver.java:29) at com.raizlabs.android.dbflow.structure.ModelAdapter.save(ModelAdapter.java:185) at com.raizlabs.android.dbflow.structure.BaseModel.save(BaseModel.java:62) at com.consoleco.console.object.Message.<init>(Message.java:63) at com.consoleco.console.page.SupportPage$2$1.onResponse(SupportPage.java:123) at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)at android.os.Handler.handleCallback(Handler.java:808) at android.os.Handler.dispatchMessage(Handler.java:103) at android.os.Looper.loop(Looper.java:193)at android.app.ActivityThread.main(ActivityThread.java:5345) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) at dalvik.system.NativeStart.main(Native Method)

I tested these: I increased integer of version = MyDatabase.VERSION I increased app versionCode I disabled Instant Run

But the problem not solved.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
simon-the-canadiancommented, Sep 15, 2017

Did you create a migration for the incremented database version? This would be the migration if your database version was bumped up to version 6 and your new column was called “new_column”.

@Migration(version = 6, database = BusySdkDatabase.class)
public class FiveToSix extends BaseMigration
{
    @Override
    public void migrate(DatabaseWrapper database)
    {
        database.execSQL("ALTER TABLE `Database_Model` ADD COLUMN `new_column` TEXT;");
    }
}
1reaction
amanflocommented, Dec 13, 2017

Below is my migration class @Migration(version = 7, database = XYZDatabase.class) public class Migration6 extends BaseMigration {

@Override
public void migrate(DatabaseWrapper database) {
    database.execSQL("ALTER TABLE `User` ADD COLUMN `username` TEXT;");
}

}

but it still table User has no column named username (code 1): , while compiling: INSERT INTO User(userId,name,phone,thumb,placeholder,username) VALUES (?,?,?,?,?,?) crash.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does my database crash after adding a new column?
I am trying to add a new column into an SQLiteDatabase but every time I try to run the code with the new...
Read more >
App Crashes and Restarts when I create a new table in my ...
I have created a database for my application and I am trying to create a new table in the database. After I create...
Read more >
CoreData loadPersistentStores error | Apple Developer Forums
Recently I update my App a new version in App Store . What I do is only add a new Entity and add...
Read more >
Migrating Room databases | Android Developers
Note: If your app's database falls back to destructive migrations, or if there are no migration paths that add a column with a...
Read more >
App changes are not captured in the spreadsheet or the app
If you have a hundred empty rows followed by a row with some text in it, AppSheet will insert new entries after that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found