© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•11mo ago
ExtraSaturated

pgTableCreator on creating constraints

Hello !
I'm very confused as there is nothing about the
pgTableCreator
pgTableCreator
in the docs and i don't understand the api correctly between this and the regular
pgTable
pgTable
why they behave differently?

anyway, that's not my issue what i currently have is:
export const contacts = createTable(
  "contacts",
  {
    email: varchar("email")
      //
      .primaryKey(),

    first_name: varchar("first_name"),
    last_name: varchar("last_name"),

    phone_number: varchar("phone_number")
      //
      .unique(),

    created_at: timestamp("created_at", { withTimezone: true })
      //
      .default(sql`CURRENT_TIMESTAMP`)
      .notNull(),
  },
  (table) => ({
    phone_number: check("phone_number_check", sql`LENGTH(${table.phone_number}) >= 10`),
  }),
);
export const contacts = createTable(
  "contacts",
  {
    email: varchar("email")
      //
      .primaryKey(),

    first_name: varchar("first_name"),
    last_name: varchar("last_name"),

    phone_number: varchar("phone_number")
      //
      .unique(),

    created_at: timestamp("created_at", { withTimezone: true })
      //
      .default(sql`CURRENT_TIMESTAMP`)
      .notNull(),
  },
  (table) => ({
    phone_number: check("phone_number_check", sql`LENGTH(${table.phone_number}) >= 10`),
  }),
);


My issue is that, the constraint is never created

looking at the doc
export const users = pgTable(
  "users",
  {
    id: uuid().defaultRandom().primaryKey(),
    username: text().notNull(),
    age: integer(),
  },
  (table) => [
    check("age_check1", sql`${table.age} > 21`),
  ]
);
export const users = pgTable(
  "users",
  {
    id: uuid().defaultRandom().primaryKey(),
    username: text().notNull(),
    age: integer(),
  },
  (table) => [
    check("age_check1", sql`${table.age} > 21`),
  ]
);


but the difference is that the anon function can accept an array, mine doesn't .. so if anyone can explain why is and what i missed..

Thanks !
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

Are postgres CONSTRAINTS supported when creating a table schema?
Drizzle TeamDTDrizzle Team / help
3y ago
Is is possible to use pgSchema with pgTableCreator
Drizzle TeamDTDrizzle Team / help
7mo ago
Deferrable foreign key constraints
Drizzle TeamDTDrizzle Team / help
3y ago
How am I supposed to put unique constraints on columns
Drizzle TeamDTDrizzle Team / help
3y ago