我在Android SQLite数据库中工作。我将它从版本1升级到版本2。
onUpgrade
方法按预期调用。
我的代码:
sqLiteDatabase.execSQL("ALTER TABLE " + Contracts.DateActivities.TABLE_NAME + " ADD COLUMN " + Contracts.DateActivities.C_GROUP + " INTEGER DEFAULT 0;");
我一直收到同样的错误:
Caused by: android.database.sqlite.SQLiteException: near "group": syntax error (code 1): , while compiling: ALTER TABLE DateActivities ADD group INTEGER DEFAULT 0
我做错了什么?
我尝试过的其他变体:
sqLiteDatabase.execSQL("ALTER TABLE " + Contracts.DateActivities.TABLE_NAME + " ADD COLUMN " + Contracts.DateActivities.C_GROUP + " INTEGER DEFAULT 0;");
sqLiteDatabase.execSQL("ALTER TABLE " + Contracts.DateActivities.TABLE_NAME + " ADD COLUMN " + Contracts.DateActivities.C_GROUP + " int DEFAULT 0;");
sqLiteDatabase.execSQL("ALTER TABLE " + Contracts.DateActivities.TABLE_NAME + " ADD " + Contracts.DateActivities.C_GROUP + " INTEGER DEFAULT 0;");
答案 0 :(得分:4)
我怀疑 Contracts.DateActivities.C_GROUP 是“GROUP”(或“群组”或“群组”或...大小写无关紧要),这是一个保留关键字表示SQLite ...并且不能用于列名