drizzle-team / drizzle-team/drizzle-orm
[BUG]: postgres insert and generatedAlwaysAsIdentity tries to insert null value
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Report hasn't been filed before.
- [X] 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
```typescript
export const materials = pgTable("materials", {
id: integer().primaryKey().generatedAlwaysAsIdentity(),
name: varchar({ length: 255 }),]
});
```
and executing
```typescript
drizzleDb
.insert(materials)
.values({
name: "my name"
})
.returning();
```
The generated SQL will is
```sql
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
Contributor guide
Assessment
This issue has not been assessed yet.