Jump to content

ON UPDATE CASCADE problem


tofuwarrior

Recommended Posts

Hi All,

 

This is my first time with foreign keys and I can see they are amazing but this has me stumped.

 

Any help, really gratefully received,

 

I have 2 tables

 

cms_objects

cms_users.

 

Each has an id column.

 

I have set up a foreign key on cms_users.id referencing cms_objects.id with ON DELETE CASCADE ON UPDATE CASCADE

 

When I delete from cms_objects it cascades fine and deletes the relevant cms_users record.

 

BUT when I for example try to update a row in cms_objects which has id =1(exists in cms_users) to be id =15 the change does not cascade changing the cms_users id 1 to be 15.

 

Am I missing something obvious?

 

Thanks,

 

TW

Link to comment
https://forums.phpfreaks.com/topic/73790-on-update-cascade-problem/
Share on other sites

My guess is you try to change an id on something and then it tries to update the id on the other table, but there the id is a unique value field and most likely also auto_increment, which will wreak havoc. MySQL knows that and does not allow it by default. Look at the manual around for the cascade descriptions, i thought i saw it mentioned there.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.