Questions tagged [cascading-deletes]

The concept of SQL databases deleting rows that refer (via a foreign key) to a deleted row.

The concept of SQL databases deleting rows that refer (via a foreign key) to a deleted row. The deletion is performed recursively and enabled with the ON DELETE CASCADE property of the foreign key.

587 questions
7
votes
1 answer

Why doesn't my model's "on_delete=models.CASCADE," generate a cascading foreign key constraint?

I am using Django, Python 3.7, and PostgreSQL 9.5. How do I mark up my model such taht a cascading foreign key constraint gets generated? I currently have this in my models.py file ... class ArticleStat(models.Model): article =…
Dave
  • 15,639
  • 133
  • 442
  • 830
7
votes
2 answers

Django cascade delete and post_delete signal

In my application post_delete signals being recorded in a specific model and when it was removed. class A(models.Model): ... class B(models.Model): a = models.ForeignKey('A') class C(models.Model): b = models.ForeignKey('B') def…
7
votes
3 answers

Delete multi level in cakephp ( chain delete )

I want to delete all dependent rable record My association Branch Model var $hasMany =array( 'Dealbranch' => array( 'className' => 'Dealbranch', 'foreignKey' => 'DLB_BR_ID', 'dependent' =>true ) ); Dealbranch…
Er.KT
  • 2,852
  • 1
  • 36
  • 70
7
votes
3 answers

ON DELETE CASCADE option not in generated when using ddl schema generation on Mysql

In a Maven-Spring-Hibernate-MySql running on Tomcat web app I'm using hibernate ddl to generate my DB schema with MySQL5InnoDBDialect. The schema is generated just fine except the cascade option for foreign-keys. For example I have this structure: A…
forhas
  • 11,551
  • 21
  • 77
  • 111
7
votes
2 answers

Performance considerations on deleting Managed Objects using Cascade rule in Core Data

I searched within SO but I didn't find a any suggestions to boost performances on deleting Managed Object in Core Data when dealing with relationships. The scenario is quite simple. As you can see there are three different entities. Each entity is…
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
6
votes
2 answers

How to delete all related records from different MySQL tables

I have two tables in my database: 'stories' and 'votes'. The stories table contains all information about an article (e.g. title, body, author name, etc.). The votes table contains all votes on all articles. There is a field in votes called…
Ilja
  • 44,142
  • 92
  • 275
  • 498
6
votes
2 answers

OneToOne relation with the User model (django.contrib.auth) without cascading delete

I'm a bit confused about how the OneToOneField works when deletion comes into play. The only quasi-authoritative info I can find is from this thread on django-developers: I don't know if you discovered this yet, but the delete is working in one…
Jordan Reiter
  • 20,467
  • 11
  • 95
  • 161
6
votes
0 answers

Disable cascade delete on a table globally for entity framework

Looking for some help with Entity Framework cascade delete. We initially had cascade delete disable globally…
Michael Esteves
  • 1,445
  • 3
  • 21
  • 38
6
votes
1 answer

nhibernate does not cascade delete children

The scenario is as follows, I have 3 objects (i simplified the names) named Parent, parent's child & child's child parent's child is a set in parent, and child's child is a set in child. mapping is as follows (relevant parts) parent
6
votes
2 answers

ON DELETE CASCADE is not working is in sqlite3 in ios

I created a .sqlite file in ios programatically like below by enabling pragma foreignkeys ON NSFileManager *theFileManager = [NSFileManager defaultManager]; if ([theFileManager fileExistsAtPath:[self getDatabasePath]] == NO) { …
Karthik Mitta
  • 335
  • 3
  • 13
6
votes
2 answers

How can I make a cascade deletion in a one_to_many relationship in Rails ActiveRecord?

I have a model in rails with one_to_many relationship. When I delete the father, I'd like to delete all childrens. How should I do it? I want to delete all orders and its items when I delete a user My models are: class User < ActiveRecord::Base …
Daniel Cukier
  • 11,502
  • 15
  • 68
  • 123
6
votes
2 answers

Error PostgreSQL delete with INNER JOIN

Postgres 8.4 DELETE FROM processing_transaction AS pt INNER JOIN processing_transaction_movement AS ptm ON pt.processing_transaction_id = ptm.processing_transaction_id LEFT OUTER JOIN test_package tesp ON pt.test_package_id =…
k1000
  • 145
  • 1
  • 1
  • 7
5
votes
2 answers

How to Delete in a many to many relationship?

I have a many to many relationship: Product has many Categories and Category has Many Products. Say I have Shopping Category Food Category Product A - Shopping Category, Food Category Product B - Shopping Category Now I delete Shopping…
5
votes
3 answers

Entity Framework Cascading Deletes & Lazy Loading

I am using the Northwind sample database. I have this code: var db = new NorthwindEntities(); int id = 2; // Example var delObject = (from o in db.Orders.Include("Order_Details") where o.OrderID == id select…
5
votes
2 answers

SQLite cascading delete

The parent table is: CREATE TABLE BHEAD ( ID INTEGER primary key asc, DESCR TEXT, LINECTR INT, UNITCTR INT) The child table is: CREATE TABLE BDET ( ID INTEGER primary key asc, BID INTEGER, BCODE TEXT, QTY INTEGER, FOREIGN KEY (BID) REFERENCES…
David He
  • 394
  • 1
  • 6
  • 16