gpt4 book ai didi

mysql - 模式创建后抛出错误

转载 作者:行者123 更新时间:2023-11-29 07:27:35 25 4
gpt4 key购买 nike

CREATE TABLE nodes (
id INTEGER PRIMARY KEY NOT NULL,
lat REAL,
lon REAL,
user TEXT,
uid INTEGER,
version INTEGER,
changeset INTEGER,
timestamp TEXT
); # this worked

CREATE TABLE nodes_tags (
id INTEGER,
key TEXT,
value TEXT,
type TEXT,
FOREIGN KEY (id) REFERENCES nodes(id)
); # this did not work

CREATE TABLE ways (
id INTEGER PRIMARY KEY NOT NULL,
user TEXT,
uid INTEGER,
version TEXT,
changeset INTEGER,
timestamp TEXT
); # this worked

CREATE TABLE ways_tags (
id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
type TEXT,
FOREIGN KEY (id) REFERENCES ways(id)
); # this did not work

CREATE TABLE ways_nodes (
id INTEGER NOT NULL,
node_id INTEGER NOT NULL,
position INTEGER NOT NULL,
FOREIGN KEY (id) REFERENCES ways(id),
FOREIGN KEY (node_id) REFERENCES nodes(id)
); # this did not work

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' value TEXT, type TEXT, FOREIGN KEY (id) REFERENCES nodes(id) )' at line 3

逗号在此位置无效输入

最佳答案

Key 是一个 Reserved Keyword in MySQL .您真的应该避免将其用作表/列名称。考虑将其命名为其他名称;否则你将不得不在它周围使用反引号。

CREATE TABLE nodes_tags (
id INTEGER,
`key` TEXT, -- I'd prefer renaming it. eg: node_key
value TEXT,
type TEXT,
FOREIGN KEY (id) REFERENCES nodes(id)
);

CREATE TABLE ways_tags (
id INTEGER NOT NULL,
`key` TEXT NOT NULL, -- I'd prefer renaming it. eg: ways_tags_key
value TEXT NOT NULL,
type TEXT,
FOREIGN KEY (id) REFERENCES ways(id)
);

关于mysql - 模式创建后抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53062891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com