Invalid Input Value for Enum

Hello! I am using a enum but running into a weird issue when trying to set the value as one of options in enum. The following is the sections from my schema: Error: Error: invalid input value for enum status: "expired" Drizzle Schema Table:
export const discordVerification = pgTable("discord_verification", {
code: varchar("code", { length: 255 }).notNull().primaryKey(),
createdAt: timestamp("created_at").notNull().defaultNow(),
clerkID: varchar("clerk_id", { length: 255 }),
discordUserID: varchar("discord_user_id", { length: 255 }),
discordUserTag: varchar("discord_user_tag", { length: 255 }),
discordProfilePhoto: varchar("discord_profile_photo", { length: 255 }),
discordName: varchar("discord_name", { length: 255 }),
status: discordVerificationStatus("status").notNull().default("pending"),
});
export const discordVerification = pgTable("discord_verification", {
code: varchar("code", { length: 255 }).notNull().primaryKey(),
createdAt: timestamp("created_at").notNull().defaultNow(),
clerkID: varchar("clerk_id", { length: 255 }),
discordUserID: varchar("discord_user_id", { length: 255 }),
discordUserTag: varchar("discord_user_tag", { length: 255 }),
discordProfilePhoto: varchar("discord_profile_photo", { length: 255 }),
discordName: varchar("discord_name", { length: 255 }),
status: discordVerificationStatus("status").notNull().default("pending"),
});
Drizzle Schema Enum:
export const discordVerificationStatus = pgEnum("status", [
"pending",
"expired",
"accepted",
"rejected",
]);
export const discordVerificationStatus = pgEnum("status", [
"pending",
"expired",
"accepted",
"rejected",
]);
Any idea why this might be? Thanks!
Solution:
Update for anyone who finds this in the future, I went ahead and found the following article which I used to modify the migration. All seems to be working now! Article: https://www.munderwood.ca/index.php/2015/05/28/altering-postgresql-columns-from-one-enum-to-another/ New Migration:...
Jump to solution
3 Replies
Angelelz
Angelelz11mo ago
Can you show the migration that was generated for that enum?
Liam
LiamOP11mo ago
Hey @Angelelz! Apologies for the delay. I solved the first part, which is that I had 2 enums sharing the name status. I have now updated the name of it and the other enum that shared the name but am running into a issue applying this migration. I get the error: PostgresError: column "status" cannot be cast automatically to type discord_status Here is the migration:
DO $$ BEGIN
CREATE TYPE "discord_status" AS ENUM('pending', 'expired', 'accepted', 'rejected');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "invite_status" AS ENUM('pending', 'accepted', 'declined');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
ALTER TABLE "discord_verification" ALTER COLUMN "status" SET DATA TYPE discord_status;--> statement-breakpoint
ALTER TABLE "invites" ALTER COLUMN "status" SET DATA TYPE invite_status;
DO $$ BEGIN
CREATE TYPE "discord_status" AS ENUM('pending', 'expired', 'accepted', 'rejected');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "invite_status" AS ENUM('pending', 'accepted', 'declined');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
ALTER TABLE "discord_verification" ALTER COLUMN "status" SET DATA TYPE discord_status;--> statement-breakpoint
ALTER TABLE "invites" ALTER COLUMN "status" SET DATA TYPE invite_status;
Solution
Liam
Liam11mo ago
Update for anyone who finds this in the future, I went ahead and found the following article which I used to modify the migration. All seems to be working now! Article: https://www.munderwood.ca/index.php/2015/05/28/altering-postgresql-columns-from-one-enum-to-another/ New Migration:
DO $$ BEGIN
CREATE TYPE "discord_status" AS ENUM('pending', 'expired', 'accepted', 'rejected');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "invite_status" AS ENUM('pending', 'accepted', 'declined');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
ALTER TABLE "discord_verification" ALTER COLUMN "status" DROP DEFAULT;
ALTER TABLE "discord_verification" ALTER COLUMN "status" SET DATA TYPE discord_status USING "status"::text::discord_status;--> statement-breakpoint
ALTER TABLE "discord_verification" ALTER COLUMN "status" SET DEFAULT 'pending';
ALTER TABLE "invites" ALTER COLUMN "status" DROP DEFAULT;
ALTER TABLE "invites" ALTER COLUMN "status" SET DATA TYPE invite_status USING "status"::text::invite_status;
ALTER TABLE "invites" ALTER COLUMN "status" SET DEFAULT 'pending';
DO $$ BEGIN
CREATE TYPE "discord_status" AS ENUM('pending', 'expired', 'accepted', 'rejected');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "invite_status" AS ENUM('pending', 'accepted', 'declined');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
ALTER TABLE "discord_verification" ALTER COLUMN "status" DROP DEFAULT;
ALTER TABLE "discord_verification" ALTER COLUMN "status" SET DATA TYPE discord_status USING "status"::text::discord_status;--> statement-breakpoint
ALTER TABLE "discord_verification" ALTER COLUMN "status" SET DEFAULT 'pending';
ALTER TABLE "invites" ALTER COLUMN "status" DROP DEFAULT;
ALTER TABLE "invites" ALTER COLUMN "status" SET DATA TYPE invite_status USING "status"::text::invite_status;
ALTER TABLE "invites" ALTER COLUMN "status" SET DEFAULT 'pending';
Want results from more Discord servers?
Add your server