drizzle-team / drizzle-team/drizzle-orm
[BUG]: INSERT automatically includes ALL schema columns, even when not provided in .values() Drizzle
- 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.44.7
### What version of `drizzle-kit` are you using?
0.0.0
### Other packages
_No response_
### Describe the Bug
Issue: INSERT automatically includes ALL schema columns, even when not provided in .values() Drizzle is including columns in INSERT statements that I'm not explicitly providing in .values(). For nullable columns, it automatically sets them to NULL, which causes errors when the column doesn't exist in the database.
Example schema
```ts
export const users = sqliteTable("users", {
id: integer("id").primaryKey(),
name: text("name").notNull(),
email: text("email")
});```
Example Insert:
```ts
await db.insert(users).values({
id: 1,
name: "John",
// I'm NOT providing email
});
```
Generated SQL:
```sql
INSERT INTO "users" ("id", "name", "email")
VALUES (1, 'John', NULL)
```
Why This Matters: When you have multiple environments (dev, staging, production), your code and database schema don't always match across all environments at the same time.
I add email column to my TypeScript schema
I deploy to dev → migration runs → column exists ✅
I deploy to staging → migration runs → column exists ✅
I deploy to production → migration hasn't run yet → column doesn't exist ❌
The same code works in dev and staging but breaks in production because Drizzle includes the email column in the INSERT statement even though I never asked for it.
The root issue: Drizzle treats the TypeScript schema as the absolute source of truth and includes ALL nullable columns in INSERT statements (setting them to NULL), regardless of what I pass to .values().
What I expect: Only insert the columns I explicitly provide. If I don't include email in my .values() object, don't add it to the SQL INSERT statement.
Contributor guide
Research direction
Reproduce the issue with the shown SQLite users schema and insert values, then trace the generated INSERT SQL to find why the omitted email column is included. Done means the SQL includes only columns provided in .values(), so the insert succeeds when the database lacks email; add or update a regression test for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sqlite, typescript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100