Skip to content

Commit 983e9c9

Browse files
committed
docs: update database migrations foreign keys constraints
1 parent c1cd2c3 commit 983e9c9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/content/1.docs/2.features/database.md

+16
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,19 @@ INSERT OR IGNORE INTO admin_users (id, email, password) VALUES (1, '[email protected]
414414
::note
415415
These queries run after all migrations are applied but are not tracked in the `_hub_migrations` table. Use this for operations that should run when deploying your project.
416416
::
417+
418+
### Foreign Key Constraints
419+
420+
If you are using [Drizzle ORM](/docs/recipes/drizzle) to generate your database migrations, note that is uses `PRAGMA foreign_keys = ON | OFF;` in the generated migration files. This is not supported by Cloudflare D1 as they support instead [defer foreign key constraints](https://developers.cloudflare.com/d1/sql-api/foreign-keys/#defer-foreign-key-constraints).
421+
422+
You need to update your migration file to use `PRAGMA defer_foreign_keys = on|off;` instead:
423+
424+
```diff [Example]
425+
-PRAGMA foreign_keys = OFF;
426+
+PRAGMA defer_foreign_keys = on;
427+
428+
ALTER TABLE ...
429+
430+
-PRAGMA foreign_keys = ON;
431+
+PRAGMA defer_foreign_keys = off;
432+
```

0 commit comments

Comments
 (0)