“FOREIGN”附近的Sqlite异常?

时间:2016-08-25 06:41:40

标签: java android mysql sqlite

  String CREATE_SUBCATEGORY_TABLE = "CREATE TABLE " + TABLE_SUBCATEGORY_LIST+ "("
            + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + KEY_NAME + " TEXT,"
            + KEY_DESC + " TEXT,"+ KEY_CATEGORY_ID + " INTEGER,"
            + KEY_CONTENT1+" TEXT,"+ KEY_CONTENTTYPE1 + " TEXT,"
            + KEY_CONTENT2+" TEXT,"+ KEY_CONTENTTYPE2 + " TEXT,"
            + KEY_CONTENT3+" TEXT,"+ KEY_CONTENTTYPE3 + " TEXT,"
            + KEY_CONTENT4+" TEXT,"+ KEY_CONTENTTYPE4 + " TEXT,"
            + KEY_CONTENT5+" TEXT,"+ KEY_CONTENTTYPE5 + " TEXT,"
            + KEY_CONTENT6+" TEXT,"+ KEY_CONTENTTYPE6 + " TEXT,"
            + KEY_ORDERID+" INTEGER,"+ KEY_STATUS+" TEXT,"
            + KEY_UPDATED+" TEXT, FOREIGN KEY ("+KEY_CATEGORY_ID+") REFERENCES "+CAT_TABLE+"("+KEY_CATEGORY_ID+")";

我现在收到以下错误: -

 android.database.sqlite.SQLiteException: near ")": syntax error (code 1): , while compiling: CREATE TABLE subcategory_list(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,subcategory_name TEXT,subcategory_shdesc TEXT,category_id INTEGER,content1 TEXT,content_type1 TEXT,content2 TEXT,content_type2 TEXT,content3 TEXT,content_type3 TEXT,content4 TEXT,content_type4 TEXT,content5 TEXT,content_type5 TEXT,content6 TEXT,content_type6 TEXT,order_id INTEGER,status TEXT,updated TEXT, FOREIGN KEY (category_id) REFERENCES category_list(category_id)

任何人都可以指出我的错误。任何帮助或建议表示赞赏。谢谢。

2 个答案:

答案 0 :(得分:3)

在最后一行修改一些拼写错误:

+ KEY_UPDATED + " TEXT," //added , and space
+" FOREIGN KEY (" + KEY_CATEGORY_ID + ") REFERENCES " 
+ CAT_TABLE + "("+KEY_CATEGORY_ID+"))"; //added "CREATE TABLE closing parenthesis"

答案 1 :(得分:2)

在最后一行添加空格前和"TEXT"后面的逗号。

您还必须关闭最后一个括号。

你的最后一行看起来是这样的:

+ KEY_UPDATED+" TEXT," +" FOREIGN KEY ("+KEY_CATEGORY_ID+") REFERENCES "+CAT_TABLE+"("+KEY_CATEGORY_ID+"))";

你也可以省略" +"在TEXT和FOREIGN KEY之间,因为你只是加入了两个字符串。

+ KEY_UPDATED+" TEXT, FOREIGN KEY ("+KEY_CATEGORY_ID+") REFERENCES "+CAT_TABLE+"("+KEY_CATEGORY_ID+"))";