Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.