Skip to content

Fix Drizzle Kit Push Error – Schema Push Fails

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Fix Drizzle Kit Push Error. We cover key concepts, practical examples, and best practices.

You run drizzle-kit push:pg and get: "Error: relation 'users' already exists" — or "Error: column 'email' of relation 'users' already exists". The database was already partially migrated, and the push command can't reconcile the state.

Wrong ❌

// src/db/schema.ts
import { pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core';

export const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name'),
  email: text('email').unique(),
  createdAt: timestamp('created_at').defaultNow(),
});

```bash
npx drizzle-kit push:pg

Error:

❌ Error: relation "users" already exists

The `users` table was created by a previous run. The `push` command tries to create it again because the schema snapshot is missing or stale.

## Right ✅

```typescript
// drizzle.config.ts
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
  schema: './src/db/schema.ts',
  out: './drizzle',
  dialect: 'postgresql',
  dbCredentials: {
    url: process.env.DATABASE_URL!,
  },
});

```bash
# Generate proper migration files first
npx drizzle-kit generate

# Then push (or use migrate in code)
npx drizzle-kit push:pg

**If the database is out of sync with the schema:**

```bash
# Check the current state
npx drizzle-kit check:pg

**To force sync (development only):**

```bash
npx drizzle-kit push:pg --force
# Drops conflicting objects and recreates them

**Use migrations instead of push:**

```bash
# Generate migration
npx drizzle-kit generate

# Apply migration
npx tsx src/db/migrate.ts

```<a href="/programming-languages/typescript/">typescript</a>
// src/db/migrate.ts
import { migrate } from 'drizzle-orm/node-postgres/migrator';
import { db } from './db';

await migrate(db, { migrationsFolder: './drizzle' });

**Snapshot conflict resolution:**

If the `drizzle` directory has a stale snapshot:

```bash
# Delete the drizzle directory and regenerate
rm -rf drizzle
npx drizzle-kit generate
npx drizzle-kit push:pg

## Root Cause

`drizzle-kit push` compares the current database schema against the Drizzle schema definition. If the database has tables that match the schema (from a previous push), the state is inconsistent because the snapshot file doesn't match. `push` expects an empty or perfectly synced database.

## Prevention

- Use `generate` + `migrate` for any shared or production database.
- Use `push` only for quick prototyping on empty databases.
- Run `drizzle-kit check` before `push` to preview changes.
- Keep the `drizzle/` directory in version control to track schema state.


## Common Mistakes with kit push error

1. **Forgetting `deriving (Show, Eq)` on custom data types needed for debugging**
2. **Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable**
3. **Using `head` and `tail` instead of pattern matching, causing runtime errors on empty lists**

These mistakes appear frequently in real-world DRIZZLE code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

## Practice Exercise

**Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.**

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

## FAQ

<details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: What's the difference between `push` and `generate`?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: <code>push</code> directly applies schema changes to the database. <code>generate</code> produces SQL migration files that can be reviewed and applied later.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Does `push` work with MySQL?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Yes — <code>drizzle-kit push:mysql</code> for MySQL, <code>push:pg</code> for <a href="/databases/postgresql/">PostgreSQL</a>, <code>push:sqlite</code> for SQLite.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Can I use `push` in production?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Not recommended — use migrations for production. <code>push</code> may drop data if columns are removed from the schema.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: How do I preview what `push` will do?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Use <code>drizzle-kit push:pg --dry-run</code> to see the SQL without executing.</p>
</div></details>

---

*Drizzle Kit is covered in the [DodaTech Drizzle ORM course](https://dodatech.com/courses/drizzle).*

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro