If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Foreign Key Constraint Problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-26-04, 17:17
hbc1981 hbc1981 is offline
Registered User
 
Join Date: Mar 2004
Posts: 1
Foreign Key Constraint Problem

Hi,

I have a MySQL database with some foreign key contstraints.

All tables are InnoDB type. The main table is Restaurant. It references the Type Of Restaurant table and the Price Range table with a foreign key constraints as follows:

alter table Restaurant
add (
constraint RESTAURANT_F2 FOREIGN KEY (PriceName) references PriceRange(Name) ON DELETE CASCADE ON UPDATE CASCADE,
constraint RESTAURANT_F1 FOREIGN KEY (TypeName) references TypeOfRestaurant(Name) ON DELETE CASCADE ON UPDATE CASCADE
);


When I try and update the TypeName of a TypeOfRestaurant or the Name of a Price Range, I get the following error:

"MySQL Error: Cannot delete a parent row: a foreign key constraint fails in Query"

The code I am using for the update is:

"UPDATE TypeOfRestaurant SET Name=\"$_POST[Name]\" WHERE Name=\"$_POST[OldName]\"


I thought the ON DELETE CASCASE ON UPDATE CASCADE should stop this happening (when a Name is changed, the effect should cascade) ? How can I get round this problem ?

Thanks,

Hal
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On