我用greenDAO创建了我的表结构,当更新下面的表时,我得到了以下错误:
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'=?
- 我已经检查了是否所有列都存在,它们确实存在!
- 我检查了列的名称,它们匹配
- 我检查了列名是否匹配一个关键字,但我没有找到一个(http://www.sqlite.org/lang_keywords.html)
有人知道是什么问题吗?
下面是当前的创建表查询:
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:所有我能说的是,表前缀不应该是更新查询的一部分,因为没有它们,查询工作…但奇怪的是,我所有的其他(>20)表工作…只是这个没有
当您更新任何字段时,此更新不会在实际的DB中刷新。一个解决方案,为我工作,是删除数据库中的所有表,然后再次创建所有表。在我的例子中,我的数据库为空。
参见下一个链接:如何清理/删除greenDao数据库
我刚刚遇到了同样的问题,你可以试试这个:检查表是新表还是旧表,因为我们总是使用"if not exists"创建表。PS:1.我来自中国,我的英语很差,希望你能听懂我说的话。2.