简体   繁体   中英

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)
);

Here is a SQL Fiddle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM