2011-03-30 7 views
0

foreingキーを作成しようとしています。マニュアル12アウトを確認した後、私は、この書いた:sqlite3.OperationalError:near "REFERENCES":構文エラー - 外部キーの作成

db.execute("create table if not exists table1 (id integer PRIMARY KEY, somedata integer)") 
db.execute("create table if not exists table2 (names text, REFERENCES maintable (id)") 

をし、この得た:

sqlite3.OperationalError: near "REFERENCES": syntax error

私は何を逃したのですか? foreingキーを作成するにはどうしたらいいですか? ありがとうございます。

sqlite_versionはあなたの第二LIGNEが間違っている3.7.4

答えて

2
+0

で説明したように、それは

db.execute("create table if not exists table2 (names text,my_id integer, FOREIGN KEY(my_id) REFERENCES maintable (id))") 

あるべきである私はそれがあまりにも動作しません、これを試してみました。今すぐ "sqlite3.OperationalError:near") ":構文エラー" – fogbit

+1

最後にかっこがありません –

+0

確かに。ありがとう、問題は解決されます。私はもっ​​と注意深くする必要があります。 – fogbit

関連する問題