I was trying to import the sample database for postgreSQL and I ended up with this error.
Shouldn’t the psql version use CONSTRAINT rather than ALTER. I’m most likely doing something wrong
I was trying to import the sample database for postgreSQL and I ended up with this error.
Hi Mathew_Salazar,
Thanks for letting us know,
Can you give us the sql or dbml code that fails?
Thanks.
CREATE TABLE "Authors" (
"id" SERIAL PRIMARY KEY,
"name" varchar,
"genre" varchar
);
CREATE TABLE "Books" (
"id" int PRIMARY KEY,
"title" varchar,
"author_id" int,
"author_name" varchar,
"checked_in" boolean
);
CREATE TABLE "Members" (
"id" SERIAL PRIMARY KEY,
"name" varchar,
"email" varchar UNIQUE,
"phone_number" int UNIQUE,
"home_address" varchar UNIQUE
);
CREATE TABLE "Booked" (
"id" SERIAL PRIMARY KEY,
"title" varchar,
"author" varchar,
"start_date" timestamp,
"end_date" timestamp,
"member_id" int,
"member_name" varchar
);
CREATE TABLE "Available" (
"id" int PRIMARY KEY,
"author_id" varchar,
"author_name" varchar,
"book_title" varchar,
"book_id" varchar
);
CREATE TABLE "Genres" (
"id" int PRIMARY KEY,
"genre" varchar
);
ALTER TABLE "Books" ADD FOREIGN KEY ("author_name") REFERENCES "Authors" ("name");
ALTER TABLE "Members" ADD FOREIGN KEY ("id") REFERENCES "Booked" ("member_id");
ALTER TABLE "Members" ADD FOREIGN KEY ("name") REFERENCES "Booked" ("member_name");
Hi Mathew,
This is a PostgresSQL error saying that the referenced keys must be unique or be primary keys, therefore, you can add unique
constraints to Authors.name
, Booked.member_id
and Booked.member_name
to make it work in Postgres.
Keeps in mind this is not a psql forum. If you have any problems relating to import/export dbml to/from sql, we’d be more than happy to help.
Thanks.
Thank you! Sorry about that. If you can you can remove this post