PostgresError: null value in column "id" of relation "pairs" violates not-null constraint

Hello, I am fairly new to Drizzle and working with databases, so I am running into a problem that I am unsure how to solve and hope that you can help me with it.

I use Directus CMS to create all of my tables. Then, I wrote schema.ts (using introspect and making a couple of manual changes).

So, one of my tables looks like this:

export const pairs = pgTable("pairs", {
  id: uuid("id").defaultRandom().primaryKey().notNull(),
  person_a: uuid("person_a")
    .notNull()
    .references(() => users.id, { onDelete: "cascade" }),
  person_b: uuid("person_b")
    .notNull()
    .references(() => users.id, { onDelete: "cascade" }),
  has_liked: boolean("has_liked").default(true).notNull(),
});


Now whenever i try to insert new pair like this

    const [pair] = await database
        .insert(pairs)
        .values({
          person_a: data.ctx.user.id,
          has_liked: false,
          person_b: data.input.user,
        })
        .returning();


I get the following error:
PostgresError: null value in column "id" of relation "pairs" violates not-null constraint

What confuses me is that in Directus, I have checked 'ON CREATE: Generate and Save UUID,' which is working just fine.

Please help me understand how I can get around this error.
Was this page helpful?