Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: postgres insert and generatedAlwaysAsIdentity tries to insert null value #3576

Open
1 task done
ChxGuillaume opened this issue Nov 18, 2024 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@ChxGuillaume
Copy link

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.36.3

What version of drizzle-kit are you using?

not installed

Other packages

No response

Describe the Bug

When using a model like this

export const materials = pgTable("materials", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),
  name: varchar({ length: 255 }),]
});

and executing

drizzleDb
    .insert(materials)
    .values({
        name: "my name"
    })
    .returning();

The generated SQL will is

INSERT INTO "materials" ("id", "name")
VALUES (null, 'my name')

It's trying to set the ID to null just errors, thus making the insert impossible

[2024-11-18 22:43:29] [23502] ERROR: null value in column "id" of relation "materials" violates not-null constraint

I am pretty sure that the Primary Column shouldn't get an insert value

Note: I am using Postgres and tried with version 11 and 16 of postgres

@ChxGuillaume ChxGuillaume added the bug Something isn't working label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant