noties / Storm

Android SQLite database manager
Apache License 2.0
53 stars 8 forks source link

Column not found even after migration set #1

Open aemxn opened 8 years ago

aemxn commented 8 years ago

Hi,

I've incremented my DatabaseManager version from version 1, like so:

new DatabaseManager(
                Storm.getApplicationContext(),
                Constants.DB_NAME,
                2,
                /* model classes */,
                pragma
        );

And added a new column inside my Model,

@Table("group_item")
public class GroupItem {

    @Column
    @PrimaryKey
    @Autoincrement
    private long id;

    @Column
    @DBNonNull
    private long item_id;

    @Column
    @DBNonNull
    private long group_id;

    @Column
    @NewColumn(2)
    private String item_image;

    @Column
    @NewColumn(2)
    @Default("0")
    private boolean item_checked;

    @Column
    @NewColumn(2)
    private String item_description;

    // the rest of the columns

When I run the application, it keeps telling me that there is no column named item_checked.

Here's the full logcat for the error:

E/SQLiteLog: (1) table group_item has no column named item_checked E/SQLiteDatabase: Error inserting group_id=1 item_checked=false item_has_suggestion=false item_color=2131755450 item_id=13 item_urgent=true item_self_assigned=true android.database.sqlite.SQLiteException: table group_item has no column named item_checked (code 1): , while compiling: INSERT INTO group_item(group_id,item_checked,item_has_suggestion,item_color,item_id,item_urgent,item_self_assigned) VALUES (?,?,?,?,?,?,?)

Is there something I missed in the migration step? How do I fix this?

EDIT: As for the time being, I'm only uninstalling the app and install it back again.

noties commented 8 years ago

Hi! It happened to me sometimes when I was debugging and added new columns after new database version was already introduced. It could be it. If not, then it's a bug in the library. BTW, I'm developing right now a new version of Storm https://github.com/noties/Storm2.0. It has no compatibility with this version, but it has much more features & it's tested (more or less). It uses apt, so every step in migration/model parsing could be manually inspected in the generated files. Right now it lacks documentation, but I hope it should be straight-forward to start with it.