Forum Moderators: open

Message Too Old, No Replies

Mysql Foreign Key update issue

I cant update a mysql foreign key field

         

MrWhippy

9:45 pm on Apr 10, 2008 (gmt 0)

10+ Year Member



Hi,

I currently have three tables.

board
Board_id
Title

thread
Thread_id
Title
Thread_Board_id (Foreign key linked to Board_id)

post
Post_id
Post_thread_id (Foreign key linked to Thread_id)
User
Message

Now i am new to mysql, only been using it a short while and am writing a website for my hockey club, so i figured the best way to learn would be to write everything for myself. i am currently doing k.

but have hit a problem when trying to update these tables.

I am trying to update them one after the other in the same php script.
(can post up here if you like)

I keep getting a cannot update foreign key constraint error.

I was wondering if anyone had any tips for this or a good place to go and have a look i dont seem to be able to find any sites that deal with this issue, or with how to use foreign keys properly in mysql and php.

thanks in advance for any help.

MrWhippy

9:46 pm on Apr 10, 2008 (gmt 0)

10+ Year Member



Oh forgot to say the foreign keys are set to cascade on delete, and no action on update, i have tried them with blank in for update as well.

i am using an innodb table as well for all.

MrWhippy

9:23 am on Apr 15, 2008 (gmt 0)

10+ Year Member



Just to let everyone know, I have solved this problem now, if anyone else is struggling with it post up and i will try to help you out.

basically i used last_insert_id to put the last id into the foreign key and it all works good.