MontaderX
DTDrizzle Team
•Created by MontaderX on 7/10/2024 in #help
there is no unique constraint matching given keys for referenced table "users"
migration file
CREATE TABLE IF NOT EXISTS "notes" (
"id" varchar(32) PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"title" text NOT NULL,
"content" text,
"color" text DEFAULT 'bg-gray-200',
"created_at" timestamp DEFAULT now(),
"updated_at" timestamp (3),
CONSTRAINT "notes_user_id_unique" UNIQUE("user_id")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "users" (
"id" varchar(32) PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"name" text NOT NULL,
"email" text NOT NULL,
"created_at" timestamp DEFAULT now(),
"updated_at" timestamp (3),
CONSTRAINT "users_id_unique" UNIQUE("id"),
CONSTRAINT "users_user_id_unique" UNIQUE("user_id")
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "notes" ADD CONSTRAINT "notes_user_id_users_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("user_id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
CREATE TABLE IF NOT EXISTS "notes" (
"id" varchar(32) PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"title" text NOT NULL,
"content" text,
"color" text DEFAULT 'bg-gray-200',
"created_at" timestamp DEFAULT now(),
"updated_at" timestamp (3),
CONSTRAINT "notes_user_id_unique" UNIQUE("user_id")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "users" (
"id" varchar(32) PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"name" text NOT NULL,
"email" text NOT NULL,
"created_at" timestamp DEFAULT now(),
"updated_at" timestamp (3),
CONSTRAINT "users_id_unique" UNIQUE("id"),
CONSTRAINT "users_user_id_unique" UNIQUE("user_id")
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "notes" ADD CONSTRAINT "notes_user_id_users_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("user_id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
3 replies