zev
zev
DTDrizzle Team
Created by zev on 4/12/2024 in #help
Mysterious Postgres Schema Issue
Update 3 -- Resolved: Just dropped my database and recreated it, this fixed the issue somehow. If anyone knows why this may have worked please let me know cause I'm curous.
4 replies
DTDrizzle Team
Created by zev on 4/12/2024 in #help
Mysterious Postgres Schema Issue
Hmm, I think that what Drizzle is generating should be valid though, right? Maybe this is an issue with my Postgres installation??
4 replies
DTDrizzle Team
Created by zev on 4/12/2024 in #help
Mysterious Postgres Schema Issue
Update 2: I think the issue could be with the order that Drizzle is creating the tables. Here's the generated SQL:
CREATE TABLE IF NOT EXISTS "course" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"aId" uuid NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "faculty" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "course" ADD CONSTRAINT "course_aId_faculty_id_fk" FOREIGN KEY ("aId") REFERENCES "faculty"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
CREATE TABLE IF NOT EXISTS "course" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"aId" uuid NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "faculty" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "course" ADD CONSTRAINT "course_aId_faculty_id_fk" FOREIGN KEY ("aId") REFERENCES "faculty"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
And if I just manually swap the order that the tables are created the code runs without errors.
4 replies