© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•16mo ago
fstodulski

[Postgres] PostgresError: type X already exists.

PostgresError: type "media_types" already exists
PostgresError: type "media_types" already exists


I have SQL like this:
CREATE TYPE "public"."media_types" AS ENUM('image', 'video');--> sta
CREATE TYPE "public"."media_types" AS ENUM('image', 'video');--> sta


It's used only here:
CREATE TABLE IF NOT EXISTS "media" (
    "id" text PRIMARY KEY NOT NULL,
    "name" text NOT NULL,
    "url" text NOT NULL,
    "filename" text NOT NULL,
    "mediaType" "media_types" NOT NULL,
CREATE TABLE IF NOT EXISTS "media" (
    "id" text PRIMARY KEY NOT NULL,
    "name" text NOT NULL,
    "url" text NOT NULL,
    "filename" text NOT NULL,
    "mediaType" "media_types" NOT NULL,


My schema is:
export const mediaTypes = z.enum(["image", "video"]);
export type MediaType = z.infer<typeof mediaTypes>;
export const mediaType = pgEnum("media_types", mediaTypes.options);

export const TB_Media = pgTable("media", {
  id: text().primaryKey().notNull().$defaultFn(nanoid),
  name: text().notNull(),

  url: text().notNull().unique(),
  filename: text().notNull(),

  mediaType: mediaType().notNull(),
export const mediaTypes = z.enum(["image", "video"]);
export type MediaType = z.infer<typeof mediaTypes>;
export const mediaType = pgEnum("media_types", mediaTypes.options);

export const TB_Media = pgTable("media", {
  id: text().primaryKey().notNull().$defaultFn(nanoid),
  name: text().notNull(),

  url: text().notNull().unique(),
  filename: text().notNull(),

  mediaType: mediaType().notNull(),


This all happend after using casting to "snake_case"
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

instanceof postgres.PostgresError not working
Drizzle TeamDTDrizzle Team / help
9mo ago
applying migrations... PostgresError: column "x" cannot be cast automatically to type x
Drizzle TeamDTDrizzle Team / help
16mo ago
relation users already exists
Drizzle TeamDTDrizzle Team / help
7mo ago
enum label already exists
Drizzle TeamDTDrizzle Team / help
2y ago