wrangler dev: 'D1_ERROR: no such table: users: SQLITE_ERROR' although migrations/0001_create_users.sql exists: apply migrations to the local DB first
Run npx wrangler d1 migrations apply <database_name> --local before (or while) wrangler dev runs, e.g. wrangler d1 migrations apply demo-db --local. wrangler dev does not apply D1 migrations by itself. The local D1 is a Miniflare SQLite file under .wrangler/state/, and it starts empty. The first query fails with ✘ [ERROR] Error: D1_ERROR: no such table: users: SQLITE_ERROR from D1DatabaseSessionAlwaysPrimary._sendOrThrow, and the client just gets Internal Server Error as plain text (so curl ... | jq says parse error: Invalid numeric literal at line 1, column 9).
In containers, run the migrate command with the same project mount as the dev server so both see the same .wrangler/state. For example: podman run --rm -v ./:/app:z -v /app/node_modules -w /app image npm run migrate while the dev container is up with the same mount. Seed data in the migration file was there immediately, with no restart. Use --remote only when you mean the real Cloudflare database, which needs a login. The database_id can stay a placeholder for local-only work. Seen with wrangler 3.114.