Error: pq: 1 columns must reference exactly 1 columns in referenced table (found 2)
0
votes
1
answer
229
views
I have a few tables and I am facing this issue most likely with the table "item".
When I remove
restaurant_id
and category_id
, it works fine.
CREATE TABLE IF NOT EXISTS restaurant
(
id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
title VARCHAR(50) NOT NULL UNIQUE
);
CREATE TABLE IF NOT EXISTS restaurant_gallery
(
id SERIAL,
restaurant_id UUID NOT NULL REFERENCES restaurant,
image VARCHAR NOT NULL,
PRIMARY KEY (id, restaurant_id)
);
CREATE TABLE IF NOT EXISTS category
(
id SERIAL NOT NULL PRIMARY KEY,
restaurant UUID NOT NULL,
label VARCHAR(25) NOT NULL,
UNIQUE (restaurant, label)
);
CREATE TABLE IF NOT EXISTS item
(
id SERIAL NOT NULL PRIMARY KEY,
restaurant_id UUID NOT NULL REFERENCES restaurant (id),
category_id SERIAL NOT NULL REFERENCES category (id),
name VARCHAR(25) NOT NULL,
UNIQUE (id, restaurant_id)
);
CREATE TABLE IF NOT EXISTS item_gallery
(
id SERIAL,
item_id INT NOT NULL REFERENCES item,
image VARCHAR NOT NULL,
PRIMARY KEY (id, item_id)
);
> Error:
pq: 1 columns must reference exactly 1 columns in referenced table (found 2)
Error: pq: 1 columns must reference exactly 1 columns in referenced table (found 2)
Failed running "sql"
Any help is highly appreciated!
Asked by Taufiq Rahman
(101 rep)
Aug 12, 2019, 10:51 AM
Last activity: Aug 12, 2019, 11:40 AM
Last activity: Aug 12, 2019, 11:40 AM