Skip to content

apply D1 migrations only fails in production #5411

@samuelcolvin

Description

@samuelcolvin

We had a fairly complex migration with transactions, it ran fine locally but when we ran it in production, we got

🚀 Running Wrangler Commands
  /usr/local/bin/npx wrangler d1 migrations apply DB --remote
   ⛅️ wrangler 4.43.0 (update available 4.45.0)
  ─────────────────────────────────────────────
  Migrations to be applied:
  ┌───────────────────────────────┐
  │ name                          │
  ├───────────────────────────────┤
  │ 0003_sync_spending_limits.sql │
  └───────────────────────────────┘
  ? About to apply 1 migration(s)
  Your database may not be available to serve requests during the migration, continue?
  🤖 Using fallback value in non-interactive context: yes
  🌀 Executing on remote database DB (25df52eb-95b6-4a4e-83aa-3880d1f1aff9):
  🌀 To execute on your local development database, remove the --remote flag from your wrangler command.
  ┌───────────────────────────────┬────────┐
  │ name                          │ status │
  ├───────────────────────────────┼────────┤
  │ 0003_sync_spending_limits.sql │ ❌     │
  └───────────────────────────────┴────────┘
  ✘ [ERROR] Migration 0003_sync_spending_limits.sql failed with the following errors:
  ✘ [ERROR] To execute a transaction, please use the state.storage.transaction() or state.storage.transactionSync() APIs instead of the SQL BEGIN TRANSACTION or SAVEPOINT statements. The JavaScript API is safer because it will automatically roll back on exceptions, and because it interacts correctly with Durable Objects' automatic atomic write coalescing. [code: 7500]
  🪵  Logs were written to "/home/runner/.config/.wrangler/logs/wrangler-2025-10-24_22-40-25_842.log"

This should absolutely have failed locally if you're going to fail it in production.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions