Questions tagged [cascade]

Cascade refers to a table-definition keyword in relational databases; it instructs the query engine to take a certain action (delete, update), when a primary key is modified, on tables linked by a foreign key.

Cascade is a keyword that helps define the behavior of database tables linked by a foreign key, when the primary table is changed. If cascade is specified in the table definition, then, for example:

  • if a row in the primary table is deleted, the corresponding rows in the linked table can be deleted
  • if a primary key is updated, then the corresponding rows can be updated
1381 questions
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
2 answers

How can I cast a QVariant to custom class?

I'm developing a BlackBerry 10 mobile application using the Momentics IDE (native SDK). I have a listview which I want to handle its items click with C++ (I need to use C++ not QML). I can get the index path using the "connect" instruction, but I…
Mohamed Jihed Jaouadi
  • 1,427
  • 4
  • 25
  • 44
21
votes
3 answers

Deletions in a many-to-many structure

I just want to check really quickly. Say I have two entities in a data model: Catalog, and Product. They have a many-to-many relationship with each other, and both are required (a Catalog must have at least one Product, and all Products must each…
Apophenia Overload
  • 2,485
  • 3
  • 28
  • 46
20
votes
1 answer

EF Core - why ClientSetNull is default OnDelete behavior for optional relations (rather than SetNull)

For optional relationships (when Foreign Key can accept Null), a new ClientSetNull behavior has been introduced since EF Core 2.0 as the default option for delete behavior DeleteBehavior.ClientSetNull. This has SetNull semantics for tracked entities…
S.Serpooshan
  • 7,608
  • 4
  • 33
  • 61
20
votes
6 answers

Entity Framework DELETE statement conflicted with the REFERENCE constraint

I’m pretty new to EF and I have a little problem. I just want to delete an item in my database. I’m using SQL Server 2012 Express, VS2012, AdventureWorks 2012. The query that I execute is the following: context = new AWEntities(); var…
user2675973
  • 227
  • 1
  • 3
  • 8
20
votes
2 answers

How does WillCascadeOnDelete in Entity Framework work?

As I understand, if I delete a parent row, its children should be deleted if I turn on cascade on delete. However, from my testing, it doesn't seem to work at all. No matter if I set WillCascaseOnDelete to true or false, it simply sets the foreign…
newman
  • 6,841
  • 21
  • 79
  • 126
20
votes
2 answers

How to force oracle to do cascade delete without dropping/recreating constraints

I've got a parent table, which has a dozen child tables referencing it. Those child tables in turn have other child tables referencing them. And so on. I need to delete a row from the main parent table cascading it all the way…
user1773602
19
votes
5 answers

Simplest way to cascade styles in react native

I see that in react native if I set a fontFamily in a, for example, a View, the inner elements do not inherit it the property. Is it there a cascade concept available in react native styling? How do I accomplish it?
R01010010
  • 5,670
  • 11
  • 47
  • 77
19
votes
1 answer

How can I delete child objects when the parent is deleted in rails?

model a: has_many :b, :dependent => :delete_all model b: belongs_to :a belongs_to :c model c: has_many :b When I delete an a, I would also like to have children b's deleted so that they get removed from any c's that may reference them. However,…
James
  • 5,273
  • 10
  • 51
  • 76
19
votes
6 answers

What is the problem with foreign key cascade multiple paths and cycles?

In SQL Server 2005 I just struck the infamous error message: Introducing FOREIGN KEY constraint XXX on table YYY may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY…
Vilx-
  • 104,512
  • 87
  • 279
  • 422
18
votes
1 answer

What Does Rails Do With Both :dependent => :destroy and cascade delete/nullify/restrict

I'm trying to decide how best to set up (if at all) foreign key constraints for my rails application. I have a model Response that belongs_to a Prompt. I would like to use :dependent => :destroy to have destroy called on every Response that…
Peter Gerdes
  • 2,288
  • 1
  • 20
  • 28
18
votes
2 answers

how to define an inverse cascade delete on a many-to-one mapping in hibernate

I have two classes A and B. Many B's can have association with a single A, hence a many-to-one relationship from B to A. I've mapped the relationship like:
Monis Iqbal
  • 1,987
  • 7
  • 26
  • 42
16
votes
2 answers

How to properly cascade delete managed objects in Core Data?

I have a Core Data model which has three entities: A, B, and C. A has a one-to-many relationship with B, and B has a many-to-many relationship with C. The delete rule for A -> B is "Cascade", and B -> A is "No Action". The delete rule for B -> C is…
CJ.
  • 1,034
  • 1
  • 9
  • 20
16
votes
3 answers

How do I use the cascade option in Symfony2 Doctrine?

I'm trying to understand the cascade option in Doctrine in Symfony2. I would like to be able to delete a child entity (and not trigger the foreign key constraint error.) I have 3 entities: Report /** * @ORM\OneToMany(targetEntity="Response",…
user1383418
  • 664
  • 3
  • 8
  • 20
15
votes
4 answers

in mysql, on delete cascade not working

similar to ON DELETE CASCADE not working in MySQL, but something is not right: The ANSI Way -- test delete cascade CREATE TABLE t1( id SERIAL PRIMARY KEY, data TEXT ); CREATE TABLE t2( id INT PRIMARY KEY REFERENCES t1(id) ON DELETE…
cc young
  • 18,939
  • 31
  • 90
  • 148
1 2
3
91 92