Comments (4)
Did you try to set client.pragma('foreign_keys = ON');
before creating your dbClient = drizzle(client, { schema })
from drizzle-orm.
@richardpasquiou Wow, that was a rookie mistake 🤦 😆
Thanks for pointing that out (the error, not the "rookie" part 😃)! That being fixed, it's still not working. Here's more details:
I'm adding a migration where I add a foreign key on a table
CREATE TABLE `elevations-2` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`group` text NOT NULL,
`description` text NOT NULL,
`vcg` real NOT NULL,
`is_default` integer NOT NULL,
`file_id` integer,
FOREIGN KEY (`file_id`) REFERENCES `file-attachments`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
INSERT INTO `elevations-2` SELECT * FROM `elevations`;--> statement-breakpoint
DROP TABLE `elevations`;
Drizzle migration tool generated the first and last SQL commands and I added the data copy in-between.
The cascading delete doesn't seem to work even when I manually delete a row from elevations
in my SQL editor (dBeaver).
PRAGMA foreign_keys;
PRAGMA foreign_keys = OFF; /* to show the difference between on and off)*/
PRAGMA foreign_keys;
PRAGMA foreign_keys = ON;
PRAGMA foreign_keys;
DELETE FROM "elevations-2" WHERE id=6;
The file-attachments
entry still exists.
Is there something wrong with the new table?
from drizzle-orm.
elevations-2 is your baby table. file-attachments is your mama table. You can't drop the baby and recursively, delete the mama entry.
It works in one way : drop the mama entry, and it will cascade on baby table
from drizzle-orm.
@richardpasquiou Oh ok, I see. The relation field should be on file-attachments
with an elevation_id
field instead of having the file_id
field on elevations
. I was hoping not to have to do that as file-attachments
links to multiple tables for a variety of entities. I guess I'll have to rethink my schema. Maybe with pivot tables... Thanks for the insight!
from drizzle-orm.
Related Issues (20)
- [BUG]: Drizzle migration dont create data base if not existed in postgres HOT 1
- [BUG]: drizzle-orm dependency missing in drizzle-kit HOT 1
- [FEATURE]: Auto-Alias Columns in Subqueries
- [BUG]: drizzle-kit introspect casing "preserve" config not working
- [FEATURE]: add luxon datetime mode to timestamp columns
- [BUG]: string values for limit causes issues but for offset they are ok HOT 1
- [FEATURE]: Join type in query system when foreign key is nullable
- [BUG]: "Offset is outside the bounds of the DataView" when querying PgGeometry field via RQB relation HOT 1
- [BUG]: `drizzle-kit push --force` fails if `__old_push_table` doesn't exist
- [BUG]:isNotNull doesn't work with and statement that searches for a varchar with - HOT 1
- [FEATURE]: Ability to get info on migration status & if db can be migrated
- [BUG]: Not inferring types properly with typescript & turborepo HOT 1
- [FEATURE]: sqlx-ts integration for magic sql operator
- [BUG]: I get `cannot insert multiple commands into a prepared statement` when migrations more than one HOT 1
- [BUG]: ALTER TABLE Migration Fails to Preserve Default Value for Column
- [BUG]: permission denied for view pg_buffercache
- [BUG]:with clouse in query return never
- [FEATURE]: support const enums
- [BUG]: Issue with SQL generation. Trying to reference a type that doesn't exist? HOT 1
- [BUG]: No warning or error when performing a migration with duplicate table columns
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drizzle-orm.