androidandroid-sqlitegreendaogreendao-generator

Altered Table Column is not able to access using Greendao-Android


Using onUpgrade in SQLiteOpenHelper, i can alter the table and new column name with a default value is added.

But when i access that particular table inside the activity,it shows only the old column count.As per alteration,it should display 4 (column count).But it shows 3 Only.

My code inside onUpgrade method:

 db.execSQL("ALTER TABLE " + MyTableDaoDao.TABLENAME + " ADD COLUMN 'VRESION_NO' INTEGER NOT NULL DEFAULT '11';");

// As im sure that table is altered because when i try to alter it again using the same column name,it shows duplicate column name sqlite exception.

For getting all columns count:

 daoSession.getMyTableDao().getAllColumns().length  // returns old table count

How can get the refreshed table details in GreenDAO?. Is there anyone come across this situation.

Thanks in advance.


Solution

  • Probably you forgot to recreate your dao code from an updated schema.

    Greendao doesn't use reflection or scan the database for creating a mapping between database and java. This mapping is created by the dao-generator. So there are two tasks if you want to update your database schema:

    1. Update the entity-classes and daos by recreating them with the new schema and increase schema-version.
    2. Implement your update strategy in your app, i.e. drop all tables and recreate them or add/change/remove the columns/tables/indexes/... that have changed since the schema-version that was active before (see my answers here and here).