-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
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.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
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:
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.