[英]unable to create join table with two foreign keys sqlite3
I get the following error after trying to create a join table with two foreign keys. 尝试使用两个外键创建联接表后,出现以下错误。
Error: near "user_id": syntax error
Here is my code for creating the join table: 这是我用于创建联接表的代码:
sqlite> CREATE TABLE reviews ( ...> id INTEGER PRIMARY KEY, ...> stars INT, ...> comment TEXT, ...> business_id INT, ...> FOREIGN KEY (business_id) REFERENCES businesses(id), ...> user_id INT, ...> FOREIGN KEY (user_id) REFERENCES users(id) ...> );
Here are the other tables: 以下是其他表格:
CREATE TABLE users ( ...> id INTEGER PRIMARY KEY, ...> first_name TEXT, ...> last_name TEXT ...> ); CREATE TABLE businesses( ...> id INTEGER PRIMARY KEY, ...> name VARCHAR(250) ...> );
The constraints should go after all the column definitions: 约束应放在所有列定义之后:
CREATE TABLE reviews (
id INTEGER PRIMARY KEY,
stars INT,
comment TEXT,
business_id INT,
user_id INT,
FOREIGN KEY (business_id) REFERENCES businesses(id),
FOREIGN KEY (user_id) REFERENCES users(id)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.