504 Gateway Time-out when applying migrations (1)

For Workes & Pages, what is the name of the domain?

example.com

What is the error number?

504

What is the error message?

504 Gateway Time-out

What is the issue or error you’re encountering

504 Gateway Time-out when applying migrations

What are the steps to reproduce the issue?

Running the following command results in the timeout error:

npx wrangler d1 migrations apply <database_name> --remote

This started happening yesterday (2024-11-17 AEDT) and still continues.

The command has working previously without error and I can still query the database without issue.

I’m logged into wrangler with an account that has full control/access.

I have other tasks that send a lot more data without issue.

The migration being applied is a small operation of adding a column to a table.

The table itself only has 5 small columns and only 450 rows so I think the migration itself shouldn’t be causing any problem.

Is there currently an issue with the migrations apply command?

Bit of a show stopper.

When I try to run the following SQL in // Cloudflare / Dashboard / Workers & Pages / D1 SQL Database / Console:

– RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE “new_Label” (

  • “labl_id” INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,*
  • “name” TEXT NOT NULL,*
  • “slug” TEXT NOT NULL,*
  • “logo” TEXT,*
  • “is_niche” BOOLEAN NOT NULL DEFAULT false*
    );
    INSERT INTO “new_Label” (“labl_id”, “logo”, “name”, “slug”) SELECT “labl_id”, “logo”, “name”, “slug” FROM “Label”;
    DROP TABLE “Label”;
    ALTER TABLE “new_Label” RENAME TO “Label”;
    CREATE INDEX “Label_slug_idx” ON “Label”(“slug”);
    PRAGMA foreign_keys=ON;
    PRAGMA defer_foreign_keys=OFF;

I receive the following error:
D1 DB exceeded its CPU time limit and was reset.

I am on the workers paid plan.

I’m now manually executing the code from the migration using the D1 console.

Even simple command like this are causing the same D1 DB exceeded its CPU time limit and was reset. error.

DROP TABLE “Label”;

The DROP TABLE “Label”; statement appears to have worked because now my site is completely broken because the label table doesn’t exist anymore.

DROP TABLE “Label”; statement caused this error:

D1 DB storage operation exceeded timeout which caused object to be reset.

I restored from backup and the site is now working again.

But a simple statement like this should not exceed CUP time and if it does, the limits need to be looked into:

DROP TABLE “Label”;

D1 DB exceeded its CPU time limit and was reset.

Surely a simple statement like this should be allowed.

It’s a table with 450 rows but the size of the table probably should not matter in any case.

This is a pretty severe limitation of the D1 product.

Please, can support look into this?

So I’ve ended up having to just rename the table that was supposed to be dropped by the migration and then renaming the new table to the name that is required.

This is a fairly severe limitation of D1 and the CPU time limits.

DROP TABLE causes:

D1 DB storage operation exceeded timeout which caused object to be reset.

Surely a DROP TABLE statement should be able to proceed no matter the size of the table?

If anyone else has this issue I suggest deleting your database and creating a new one.

I can’t explain why a simple DROP TABLE statement would raise this error:
D1 DB storage operation exceeded timeout which caused object to be reset.

I have a database reset script that drops all tables in my database that I’ve run hundreds of
times successfully but my DB must have ended up with a lock of some kind that could not be resolved.

Delete the DB and start again seems to be the solution.

I was hoping support would comment on this.

I get this is still early days for D1 and I love the product.

Everything works great with reads and writes being super fast but there are clearly some issues under the hood that need improvement.