SQLITE CREATE TABLE语法错误(代码1 SQLITE_ERROR[1])

ssm49v7z  于 2022-11-15  发布在  SQLite
关注(0)|答案(1)|浏览(170)

我需要一些帮助,我有这样的疑问:

CREATE TABLE IF NOT EXISTS staff_ratio
(id INTEGER PRIMARY KEY AUTOINCREMENT, type INTEGER CHECK ( type IN (0, 1) ) NOT NULL DEFAULT 0,
shift INTEGER CHECK ( shift IN (0, 2, 1)) NOT NULL DEFAULT 0,
personal_count INTEGER, clients INTEGER, ratio REAL, date INTEGER NOT NULL, restaurant_id INTEGER NOT NULL, FOREIGN KEY(restaurant_id) REFERENCES restaurants(id) ON DELETE CASCADE,
hotel_staff_ratio_id INTEGER NOT NULL, FOREIGN KEY(hotel_staff_ratio_id) REFERENCES hotel_staff_ratio(id) ON DELETE CASCADE)

错误:

android.database.sqlite.SQLiteException: near "hotel_staff_ratio_id": syntax error (code 1 SQLITE_ERROR[1])
lf5gs5x2

lf5gs5x21#

您混淆了列规范和表约束。
列规范(如hotel_staff_ratio_id INTEGER NOT NULL)排在第一位,表约束(如FOREIGN KEY(restaurant_id) REFERENCES restaurants(id) ON DELETE CASCADE)排在最后。
hotel_staff_ratio_id INTEGER NOT NULL移动到第一个FOREIGN KEY表格约束之前。

相关问题