简体   繁体   中英

Python SQLite3 syntax error when creating a table

I'm trying to create a table with the following command:

'CREATE TABLE users_profile(user_id INTEGER UNIQUE, FOREIGN KEY(user_id) REFERENCES users(user_id) ON DELETE CASCADE,\
    firstname TEXT, lastname TEXT, email TEXT, website TEXT,\
    picture TEXT, mobile TEXT, skype TEXT, age INTEGER, residence TEXT, gender TEXT,\
    signature TEXT, avatar TEXT)'

I get the error: 'Error near "firstname": syntax error:'

I know that the following part is causing this error: 'FOREIGN KEY(user_id) REFERENCES users(user_id) ON DELETE CASCADE'

So apparently I'm doing something wrong here, but I just can't figure out what I need to change in order to make this work. Any help would be much appreciated.

Okay, I got it working. Foreign key reference needs to be the last thing.

Like this: 'CREATE TABLE users_profile(user_id INTEGER UNIQUE, firstname TEXT, lastname TEXT, email TEXT, website TEXT,\\ picture TEXT, mobile TEXT, skype TEXT, age INTEGER, residence TEXT, gender TEXT,\\ signature TEXT, avatar TEXT, FOREIGN KEY(user_id) REFERENCES users(user_id) \\ ON DELETE CASCADE)'

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