stiba
stiba
Explore posts from servers
DTDrizzle Team
Created by stiba on 6/26/2024 in #help
Migrations complain about missing relations
I get the following error when running migrations:
PostgresError: relation "public.users" does not exist
PostgresError: relation "public.users" does not exist
The weird thing is that the table gets created in the drizzle schema, so when the migration.sql file references "public.users" it fails. The public schema is also only mentioned once in the migration file.
DO $$ BEGIN
CREATE TYPE "public"."account_type" AS ENUM('discord');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "accounts" (
"account_id" text PRIMARY KEY NOT NULL,
"account_type" "account_type" NOT NULL,
"access_token" text NOT NULL,
"refresh_token" text NOT NULL,
"user_id" integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "session" (
"id" text PRIMARY KEY NOT NULL,
"data" json NOT NULL,
"expires_at" timestamp NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "users" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar(256),
"email" varchar(256) NOT NULL,
"avatar_url" text
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "email_idx" ON "users" USING btree ("email");
DO $$ BEGIN
CREATE TYPE "public"."account_type" AS ENUM('discord');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "accounts" (
"account_id" text PRIMARY KEY NOT NULL,
"account_type" "account_type" NOT NULL,
"access_token" text NOT NULL,
"refresh_token" text NOT NULL,
"user_id" integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "session" (
"id" text PRIMARY KEY NOT NULL,
"data" json NOT NULL,
"expires_at" timestamp NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "users" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar(256),
"email" varchar(256) NOT NULL,
"avatar_url" text
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "email_idx" ON "users" USING btree ("email");
If I remove the "public". infront of "users" the migration runs fine, but every table is created in the drizzle schema. Am I doing something wrong here?
2 replies
DTDrizzle Team
Created by stiba on 3/18/2023 in #help
Applying migrations with drizzle-orm/pg-core
How would I apply all the migrations that have not yet been applied? I couldn't find any information in the docs
4 replies