Qentrah
Projects
Guides

Local D1 migrations

View as Markdown

For a D1-backed local preview, generate SQL with npm run db:generate. Build once through the Sites skill's build entrypoint (or npm run build for standalone use) to generate dist/server/wrangler.json, rebuilding if bindings change. From the project root, apply each pending migration in order:

Terminal
Shell
node --import ./scripts/sites-env.mjs ./node_modules/wrangler/bin/wrangler.js d1 execute DB --local --config dist/server/wrangler.json --persist-to .wrangler/state --file drizzle/0000_example.sql

Replace the filename with the pending migration and DB with your D1 binding name if different. Use .wrangler/state, not .wrangler/state/v3; Wrangler adds the versioned directories. Do not replay migrations already applied locally. This updates only the preview database; publishing applies production migrations separately.

Source captured: 2026-10-11