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
31
votes
4 answers

Trigger calls in cascade deleting

I have table "A" in MySQL. It has some references with cascade deleting to some other tables ("B", "C", "D" ...). I need to use a trigger when something deletes from "A". This trigger works when I delete records from "A" directly. But it doesn't…
user758690
  • 311
  • 1
  • 3
  • 3
30
votes
2 answers

How do you ensure Cascade Delete is enabled on a table relationship in EF Code first?

I would like to enable CASCADE DELETE on a table using code-first. When the model is re-created from scratch, there is no CASCADE DELETE set even though the relationships are set-up automatically. The strange thing is that it DOES enable this for…
jaffa
  • 26,770
  • 50
  • 178
  • 289
29
votes
2 answers

Cascading deletes with Entity Framework - Related entities deleted by EF

I have an issue with deletion in Entity Framework. In short, EF explicitly tries to delete an entity from the database even though I've explcitly configured EF to use cascading deletes in the database. My design: I have three entity types,…
Nitramk
  • 1,542
  • 6
  • 25
  • 42
29
votes
3 answers

How do I edit a table in order to enable CASCADE DELETE?

I have a table representing users. When a user is deleted I get: DELETE statement conflicted with the REFERENCE constraint Apparently, CASCADE DELETE is not as easy as I imagined in SQL Server, and the option needs to be added to the table. The…
RadiantHex
  • 24,907
  • 47
  • 148
  • 244
28
votes
4 answers

Django - Cascade deletion in ManyToManyRelation

Using the following related models (one blog entry can have multiple revisions): class BlogEntryRevision(models.Model): revisionNumber = models.IntegerField() title = models.CharField(max_length = 120) text = models.TextField() …
AndiDog
  • 68,631
  • 21
  • 159
  • 205
27
votes
3 answers

Why won't my GenericForeignKey cascade when deleting?

I'm creating a custom commenting system which can attache comments to any model using the contenttypes GenericForeignKey. class Comment(models.Model): body = models.TextField(verbose_name='Comment') user = models.ForeignKey(User) parent…
26
votes
2 answers

Figure out if a table has a DELETE on CASCADE

Can I know if a database have DELETE ON CASCADE with a query?
Jos3k4
  • 381
  • 1
  • 4
  • 4
24
votes
1 answer

MS SQL "ON DELETE CASCADE" multiple foreign keys pointing to the same table?

I have a problem where i need a cascade on multiple foreign keys pointing to the same table.. [Insights] | ID | Title | | 1 | Monty Python | | 2 | Spamalot | [BroaderInsights_Insights] | broaderinsight_id | insight_id | | 1 …
Daniel Upton
  • 5,561
  • 8
  • 41
  • 64
24
votes
1 answer

What is the difference between REMOVE and DELETE?

Is there a difference between : @Cascade(org.hibernate.annotations.CascadeType.REMOVE) and @Cascade(org.hibernate.annotations.CascadeType.DELETE) ?
marhatta
23
votes
1 answer

Django on_delete=models.CASCADE has no effect at SQL level

My models.py file contains: class User(models.Model): email = models.CharField(max_length=100, unique=True) password = models.CharField(max_length=100) create_time = models.DateTimeField(auto_now_add=True) class Session(models.Model): …
Rakib
  • 12,376
  • 16
  • 77
  • 113
23
votes
3 answers

iPhone Core Data: Cascading delete across a many-to-one relationship

I have two classes A and B with a many-to-one relationship from A to B (multiple A objects may reference the same B). The question is, if the delete rule on the A side is Cascade, will B be deleted only when the last referencing A is deleted or…
David Goodine
  • 529
  • 1
  • 5
  • 12
23
votes
8 answers

Core Data Relationships cause save error after delete

This question is probably a long shot. I can't figure out the errors I'm getting on my core data project when I save after I delete an entity. I have two main entities that I work with, an Outfit, and an Article. I can create them with no problem…
SooDesuNe
  • 9,880
  • 10
  • 57
  • 91
22
votes
2 answers

Entity Framework: Set Delete Rule with CodeFirst

I am using EF4 CTP 5, CodeFirst. Please see my classes first: public class Guest { [Key] public Guid GuestID { get; set; } public Language PreferredLanguage { get; set; } public Guid? LanguageID { get; set;…
21
votes
1 answer

How to set up cascading deletes in MySQL workbench?

In MySQL Workbench, how do you set up a cascading delete on a relationship? I clicked the relationship line and clicked on properties but I do not see any mention of a cascading delete option.
MadSeb
  • 7,958
  • 21
  • 80
  • 121
20
votes
3 answers

How to cascade delete over many to many table

I have a 3 tables that look like this: (source: InsomniacGeek.com) On the foreign keys I have set cascade deletes. Right now, when I delete a record in the Folder table, only the related record in the FolderItem is deleted. This is expected and…
Magnus Johansson
  • 28,010
  • 19
  • 106
  • 164
1
2
3
39 40