cloudflare / cloudflare/developer-platform

πŸ› BUG: `[7501]` error after a successfully complete migration...

Open
#39 8 comments 0 reactions 0 assignees View on GitHub
product:d1
Dominant language
No language data
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

Description

### Which Cloudflare product(s) does this pertain to?

D1

### What version of `Wrangler` are you using?

3.1.0

### What operating system are you using?

Linux (ubuntu-latest/github-actions)

### Describe the Bug

I have got a strange error when running migrations on recently created, empty D1 database. Both migrations listed below where applied and I can confirm it inspecting the database. All required tables were created with right types and right indexes, however I still got an error telling otherwise.

After rerunning the action manually, the migrations status was confirmed as already applies and no further migrations were run: `βœ… No migrations to apply!`.

Here is the run logs, from the point of applying the migrations:
```
Run pnpm run db.apply
pnpm run db.apply
shell: /usr/bin/bash -e {0}
env:
PNPM_HOME: /home/runner/setup-pnpm/node_modules/.bin
CLOUDFLARE_API_TOKEN: ***

> @*****/*****@ db.apply /home/runner/work/*****/*****/apps/*****/*****
> wrangler d1 migrations apply blog

β–² [WARNING] Processing wrangler.toml configuration:

- D1 Bindings are currently in alpha to allow the API to evolve before general availability.
Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
Note: Run this command with the environment variable NO_D1_WARNING=true to hide this message

For example: `export NO_D1_WARNING=true && wrangler `

--------------------
🚧 D1 is currently in open alpha and is not recommended for production data and traffic
🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
🚧 To give feedback, visit https://discord.gg/cloudflaredev
--------------------

Migrations to be applied:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ name β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0000_panoramic_sleeper.sql β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0001_melodic_sentry.sql β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
? About to apply [2](https://github.com/*****/*****/actions/runs/*****/jobs/*****#step:*****) migration(s)
Your database may not be available to serve requests during the migration, continue?
πŸ€– Using default value in non-interactive context: yes
πŸ•’ Creating backup...
πŸŒ€ Mapping SQL input into an array of statements
πŸŒ€ Parsing 4 statements
πŸŒ€ Executing on *****(ede788c4-771d-410a-91[3](https://github.com/*****/*****/actions/runs/*****/jobs/*****#step:*****)0-[4](https://github.com/*****/*****/actions/runs/*****/jobs/*****#step:*****)fefd3788ab[5](https://github.com/*****/*****/actions/runs/*****/jobs/*****#step:*****)):
🚣 Executed 4 commands in 21.27123999595[6](https://github.com/*****/*****/actions/runs/*****/jobs/*****#step:*****)42ms
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ name β”‚ status β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0000_*****_*****.sql β”‚ βœ… β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0001_*****_*****.sql β”‚ πŸ•’οΈ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
πŸŒ€ Mapping SQL input into an array of statements
πŸŒ€ Parsing 4 statements
πŸŒ€ Executing on blog (ede[7](https://github.com/*****/*****/actions/runs/*****/jobs/*****#step:*****)[8](https://github.com/*****/*****/actions/runs/*****/jobs/*****#step:*****)8c4-771d-410a-[9](https://github.com/*****/*****/actions/runs/*****/jobs/*****#step:*****)130-4fefd3788ab5):
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ name β”‚ status β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0000_*****_*****.sql β”‚ βœ… β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0001_*****_*****.sql β”‚ ❌ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜

❌ Migration 0001_*****_*****.sql failed with the following errors:

✘ [ERROR] Internal error: Error sending request to D1 for database ede788c4-771d-4[10](https://github.com/*****/*****/actions/runs/*****/jobs/*****#step:*****)a-9130-4fefd3788ab5 [code: 7501]

If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose
 ELIFECYCLE  Command failed with exit code 1.
Error: Process completed with exit code 1.
```

0001_*****_*****.sql
```sql
CREATE TABLE `emails` (
`id` integer PRIMARY KEY NOT NULL,
`email` text(320) NOT NULL,
`token` text(21) NOT NULL,
`timestamp` integer NOT NULL
);

CREATE UNIQUE INDEX `idx_unique_token` ON `emails` (`token`);
CREATE UNIQUE INDEX `idx_unique_email` ON `emails` (`email`);
```

0002_*****_*****.sql
```sql
CREATE TABLE `access.access` (
`id` integer PRIMARY KEY NOT NULL,
`ipid` integer NOT NULL,
`timestamp` integer NOT NULL,
FOREIGN KEY (`ipid`) REFERENCES `access.ips`(`id`)
);

CREATE TABLE `access.ips` (
`id` integer PRIMARY KEY NOT NULL,
`ip` text(45) NOT NULL,
`type` text NOT NULL
);

CREATE UNIQUE INDEX `idx_unique_ip` ON `access.ips` (`ip`);
```

Running `SELECT name, type, sql FROM sqlite_schema;` gives:

name | type | sql
-- | -- | --
d1_kv | table | CREATE TABLE d1_kv (key TEXT PRIMARY KEY, value TEXT NOT NULL)
sqlite_autoindex_d1_kv_1 | index |
__drizzle_migrations | table | CREATE TABLE __drizzle_migrations( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE, applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL )
sqlite_autoindex___drizzle_migrations_1 | index |
sqlite_sequence | table | CREATE TABLE sqlite_sequence(name,seq)
emails | table | CREATE TABLE `emails` ( `id` integer PRIMARY KEY NOT NULL, `email` text(320) NOT NULL, `token` text(21) NOT NULL, `timestamp` integer NOT NULL )
idx_unique_token | index | CREATE UNIQUE INDEX `idx_unique_token` ON `emails` (`token`)
idx_unique_email | index | CREATE UNIQUE INDEX `idx_unique_email` ON `emails` (`email`)
access.access | table | CREATE TABLE `access.access` ( `id` integer PRIMARY KEY NOT NULL, `ipid` integer NOT NULL, `timestamp` integer NOT NULL, FOREIGN KEY (`ipid`) REFERENCES `access.ips`(`id`) )
access.ips | table | CREATE TABLE `access.ips` ( `id` integer PRIMARY KEY NOT NULL, `ip` text(45) NOT NULL, `type` text NOT NULL )
idx_unique_ip | index | CREATE UNIQUE INDEX `idx_unique_ip` ON `access.ips` (`ip`)

Contributor guide

Open the contributing guide

Research direction

Start with the `wrangler d1 migrations apply` path using Wrangler 3.1.0 and the two migration SQL examples in the report. Compare the reported code 7501 failure with the resulting `sqlite_schema` and `__drizzle_migrations` entries; done means explaining or correcting the case where migrations are applied but the command exits with an error.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.