Reputation: 117
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
comma not valid input at this position
Upvotes: 1
Views: 31
Reputation: 28834
Key
is a Reserved Keyword in MySQL. You should really avoid using it as a Table/Column Name. Consider naming it to something else; otherwise you will have to use backticks around it.
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)
);
Upvotes: 1