我正在使用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;");

最佳答案

我怀疑 Contracts.DateActivities.C_GROUP 是“GROUP”(或“group”或“Group”或...大小写无关紧要),这是SQLite的保留关键字 ...,不能用于列名

10-07 12:47