j256 / ormlite-android

ORMLite Android functionality used in conjunction with ormlite-core
http://ormlite.com/
ISC License
1.59k stars 367 forks source link

java.sql.SQLException: Unknown field 'age' from the Android sqlite cursor, not in:[id, name] #72

Closed Kilnn closed 6 years ago

Kilnn commented 8 years ago

Hello I upgrade my database and add one cloumn to the table 'user' . When i do CURD first time , i got this error. This is my upgrade code in OrmLiteSqliteOpenHelper's subclass

@Override public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) { if (oldVersion < 2) { try { Dao<User, Integer> dao = DaoManager.createDao(connectionSource, User.class); dao.executeRaw("ALTER TABLE user ADD COLUMN age INTEGER;"); } catch (SQLException e) { e.printStackTrace(); } } }

luaz commented 8 years ago

Perhaps you forgot to run OrmLiteConfigUtil to regenerate ormlite_config.txt with the newly added field.

j256 commented 6 years ago

I agree with @luaz . Best of luck.