I recently tried to rename a Cloudflare D1 database.
Unfortunately, I realized that this is not possible and you have to create a new database instead.
So I first exported all the data from the old database to a db.sql
file using the export
command of Wrangler:
npx wrangler d1 export <OLD_DATABASE_NAME> --remote --output=db.sql
I then created a new database and imported the data from the db.sql
file:
npx wrangler d1 execute <NEW_DATABASE_NAME> --remote --file=db.sql
Here I came across the following error:
🌀 Starting import...
🌀 Processed 14287 queries.
🌀 Processed 27188 queries.
🌀 Processed 40239 queries.
🌀 Processed 53436 queries.
✘ [ERROR] {"D1_RESET_DO":true}
Unfortunately, neither the error message nor a quick search got me any further. So I tried various approaches and finally came up with the following solution:
- Export only the database schema:
npx wrangler d1 export <OLD_DATABASE_NAME> --remote --output=db-schema.sql --no-data
- Export only the data:
npx wrangler d1 export <OLD_DATABASE_NAME> --remote --output=db-data.sql --no-schema
- Import only the schema into the new database:
npx wrangler d1 execute <NEW_DATABASE_NAME> --remote --file=db-schema.sql
- Import only the data into the new database:
npx wrangler d1 execute <NEW_DATABASE_NAME> --remote --file=db-data.sql
This way, I was able to successfully import the data into the new database without encountering the D1_RESET_DO
error.