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]: isTable helper function is not working HOT 1
- [BUG]: Geometry type ignores SRID option
- [FEATURE]: alias of rows to insert with ON DUPLICATE KEY
- [BUG]: PG Numeric inferred as string, but is numeric at runtime HOT 1
- How to fetch one to many relationships using the select api
- [BUG]: raw SQL fields selected from subqueries should not require manually-defined aliases
- [BUG]: Persistent HTTP 400 with Vercel & drizzle-kit
- [Enhancement]: Generated type HOT 1
- [BUG]: Drizzle Studio not print result of `db.selectDistinctOn`
- [BUG]: Documentation is outdated on inArray and notInArray Methods
- Improve Filter Experience in drizzle-studio especially for Enum Columns
- [BUG]: Nullable columns do not exist in insert(table).values() HOT 3
- [FEATURE]: migrations in TypeScript / `drizzle-kit generate --typescript`
- Add support for NoSQL Databases {MongoDB especially}
- [BUG]: drizzle-orm imported operators `eq`, `lt`, etc. unable to recognize left hand "table.column" param while callback syntax works
- [BUG]: Please install latest version of "drizzle-orm" - with latest Drizzle version HOT 2
- [FEATURE]: Add support for range column types
- Trouble with Schema Changes Using drizzle-kit push Command in v0.23.0 HOT 2
- [BUG]: Drizzle Query Returns Different Result Than Select
- [BUG]: Cannot find module error when import includes '.js' file extension in TypeScript project HOT 1
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.