[英]How to use multiple foreign keys in one table in sqlite?
String Post_Code = "CREATE TABLE IF NOT EXISTS PostCode("
+ "PostCode_ID integer PRIMARY KEY, "
+ "Code string NOT NULL, "
+ "City_ID integer,"
+ "FOREIGN KEY (City_ID)"
+ "REFERENCES City (City_ID)"
+ "ON UPDATE CASCADE "
+ "ON DELETE SET NULL, "
+ "County_ID integer,"
+ "FOREIGN KEY (County_ID)"
+ "REFERENCES County (County_ID)"
+ "ON UPDATE CASCADE "
+ "ON DELETE SET NULL"
+ ");";
I believe it's most likely to be something within the first foreign key reference.我相信它很可能是第一个外键引用中的东西。
Either move all the FOREIGN KEY
definitions at the end of the statement:在语句末尾移动所有
FOREIGN KEY
定义:
CREATE TABLE IF NOT EXISTS PostCode(
PostCode_ID integer PRIMARY KEY,
Code TEXT NOT NULL,
City_ID integer,
County_ID integer,
FOREIGN KEY (City_ID) REFERENCES City (City_ID) ON UPDATE CASCADE ON DELETE SET NULL,
FOREIGN KEY (County_ID)REFERENCES County (County_ID) ON UPDATE CASCADE ON DELETE SET NULL
);
or, define each foreign key right after the definition of each column without the FOREIGN KEY
keywords:或者,在没有
FOREIGN KEY
关键字的每列定义之后立即定义每个外键:
CREATE TABLE IF NOT EXISTS PostCode(
PostCode_ID integer PRIMARY KEY,
Code TEXT NOT NULL,
City_ID integer REFERENCES City (City_ID) ON UPDATE CASCADE ON DELETE SET NULL,
County_ID integer REFERENCES County (County_ID) ON UPDATE CASCADE ON DELETE SET NULL
);
Note that there is no string
data type in SQLite.请注意,SQLite 中没有
string
数据类型。
I changed it to TEXT
.我将其更改为
TEXT
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.