问题
I created my table structure with greenDAO and when updating the following table, I'm getting the follwing error:
android.database.sqlite.SQLiteException: no such column: BODY_LOG_ENTRY._id: ,
while compiling: UPDATE BODY_LOG_ENTRY SET
'BODY_LOG_ENTRY._id'=?,
'BODY_LOG_ENTRY.FK_DAY'=?,
'BODY_LOG_ENTRY.DAY_ORDER'=?,
'BODY_LOG_ENTRY.DESCRIPTION'=?,
'BODY_LOG_ENTRY.BODY_WEIGHT'=?,
'BODY_LOG_ENTRY.BODY_SIZE'=?,
'BODY_LOG_ENTRY.BODY_FAT_FORMULA'=?,
'BODY_LOG_ENTRY.BODY_FAT_FORMULA_DATA1'=?,
'BODY_LOG_ENTRY.BODY_FAT_FORMULA_DATA2'=?,
'BODY_LOG_ENTRY.BODY_FAT_FORMULA_DATA3'=?,
'BODY_LOG_ENTRY.BODY_FAT_FORMULA_DATA4'=?,
'BODY_LOG_ENTRY.BODY_FAT_FORMULA_DATA5'=?,
'BODY_LOG_ENTRY.BODY_FAT_FORMULA_DATA6'=?,
'BODY_LOG_ENTRY.BODY_FAT_FORMULA_DATA7'=?,
'BODY_LOG_ENTRY.BODY_FAT_FORMULA_DATA8'=?,
'BODY_LOG_ENTRY.BODY_FAT_FORMULA_DATA9'=?,
'BODY_LOG_ENTRY.BODY_FAT'=?,
'BODY_LOG_ENTRY.NECK'=?,
'BODY_LOG_ENTRY.SHOULDER'=?,
'BODY_LOG_ENTRY.CHEST'=?,
'BODY_LOG_ENTRY.UNDERCHEST'=?,
'BODY_LOG_ENTRY.WAIST'=?,
'BODY_LOG_ENTRY.ARM_LEFT'=?,
'BODY_LOG_ENTRY.ARM_RIGHT'=?,
'BODY_LOG_ENTRY.FOREARM_LEFT'=?,
'BODY_LOG_ENTRY.FOREARM_RIGHT'=?,
'BODY_LOG_ENTRY.BUTT'=?,
'BODY_LOG_ENTRY.THIGHES_LEFT'=?,
'BODY_LOG_ENTRY.THIGHES_RIGHT'=?,
'BODY_LOG_ENTRY.CALVES_LEFT'=?,
'BODY_LOG_ENTRY.CALVES_RIGHT'=?
WHERE BODY_LOG_ENTRY.'_id'=?
- I already checked if all columns exist, and they do!
- I checked the names of the columns and they match
- I checked if a column name matches one keyword, but I did not find one (http://www.sqlite.org/lang_keywords.html)
does anybody have any idea what the problem could be?
Following is the current create table query:
public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "'BODY_LOG_ENTRY' (" + //
" '_id' INTEGER PRIMARY KEY ," + // 0: id
" 'FK_DAY' INTEGER NOT NULL ," + // 1: fkDay
" 'DAY_ORDER' INTEGER NOT NULL ," + // 2: dayOrder
" 'DESCRIPTION' TEXT NOT NULL ," + // 3: description
" 'BODY_WEIGHT' REAL NOT NULL ," + // 4: bodyWeight
" 'BODY_SIZE' INTEGER NOT NULL ," + // 5: bodySize
" 'BODY_FAT_FORMULA' INTEGER NOT NULL ," + // 6: bodyFatFormula
" 'BODY_FAT_FORMULA_DATA1' REAL NOT NULL ," + // 7: bodyFatFormulaData1
" 'BODY_FAT_FORMULA_DATA2' REAL NOT NULL ," + // 8: bodyFatFormulaData2
" 'BODY_FAT_FORMULA_DATA3' REAL NOT NULL ," + // 9: bodyFatFormulaData3
" 'BODY_FAT_FORMULA_DATA4' REAL NOT NULL ," + // 10: bodyFatFormulaData4
" 'BODY_FAT_FORMULA_DATA5' REAL NOT NULL ," + // 11: bodyFatFormulaData5
" 'BODY_FAT_FORMULA_DATA6' REAL NOT NULL ," + // 12: bodyFatFormulaData6
" 'BODY_FAT_FORMULA_DATA7' REAL NOT NULL ," + // 13: bodyFatFormulaData7
" 'BODY_FAT_FORMULA_DATA8' REAL NOT NULL ," + // 14: bodyFatFormulaData8
" 'BODY_FAT_FORMULA_DATA9' REAL NOT NULL ," + // 15: bodyFatFormulaData9
" 'BODY_FAT' REAL NOT NULL ," + // 16: bodyFat
" 'NECK' REAL NOT NULL ," + // 17: neck
" 'SHOULDER' REAL NOT NULL ," + // 18: shoulder
" 'CHEST' REAL NOT NULL ," + // 19: chest
" 'UNDERCHEST' REAL NOT NULL ," + // 20: underchest
" 'WAIST' REAL NOT NULL ," + // 21: waist
" 'ARM_LEFT' REAL NOT NULL ," + // 22: armLeft
" 'ARM_RIGHT' REAL NOT NULL ," + // 23: armRight
" 'FOREARM_LEFT' REAL NOT NULL ," + // 24: forearmLeft
" 'FOREARM_RIGHT' REAL NOT NULL ," + // 25: forearmRight
" 'BUTT' REAL NOT NULL ," + // 26: butt
" 'THIGHES_LEFT' REAL NOT NULL ," + // 27: thighesLeft
" 'THIGHES_RIGHT' REAL NOT NULL ," + // 28: thighesRight
" 'CALVES_LEFT' REAL NOT NULL ," + // 29: calvesLeft
" 'CALVES_RIGHT' REAL NOT NULL );"); // 30: calvesRight
// Add Indexes
db.execSQL("CREATE INDEX " + constraint + "IDX_BODY_LOG_ENTRY_FK_DAY ON BODY_LOG_ENTRY" +
" (FK_DAY);");
db.execSQL("CREATE INDEX " + constraint + "IDX_BODY_LOG_ENTRY_DAY_ORDER ON BODY_LOG_ENTRY" +
" (DAY_ORDER);");
}
PS: all I can say is, that the table prefix should not be part of the update query, because without them, the query works... but the weird thing is, that all my other (>20) tables work... just this one does not
回答1:
When you update any fields, this updates don't refresh in the actual DB. A solution that worked for me, is delete all tables in the DB and then create all tables again. In my case, my database was empty.
See the next link: How to clean/delete greenDao database
Other option is do ALTER TABLE on existing database.
回答2:
I just encountered the same problem,you can try this : check the table which is a new table or a old table ,because we always create table with "if not exists". PS: 1.I am from China,my English is poor , Pray you can understand my words. 2.the answer is for someone who will meet the same question after me.
来源:https://stackoverflow.com/questions/16835165/android-sqlite-no-such-column-error-greendao