Forums / Upgrading from 1.3.x to 1.3.9 / #1216 - Cannot add or update a child row: a foreign key constraint fails

#1216 - Cannot add or update a child row: a foreign key constraint fails

Locked

Views: 3,990

Results 1 to 9 of 9
This thread is locked. New replies are disabled.
21 Dec 2010, 5:01 AM
#1
cogmios avatar

cogmios

New Zenner

Join Date:
Jan 2008
Posts:
9
Plugin Contributions:
0

#1216 - Cannot add or update a child row: a foreign key constraint fails

I was importing a backup made with phpmyadmin (latest version of zen cart)

It works but... it gave me 1 error message on 2 alters:

#1216 - Cannot add or update a child row: a foreign key constraint fails

It did not want to do the following 2 alters:

ALTER TABLE eav_entity_attribute ADD CONSTRAINT FK_EAV_ENTITY_ATTRIBUTE_ATTRIBUTE FOREIGN KEY ( attribute_id ) REFERENCES eav_attribute ( attribute_id ) ONDELETE CASCADE ON UPDATE CASCADE ,
ADD CONSTRAINT FK_EAV_ENTITY_ATTRIBUTE_GROUP FOREIGN KEY ( attribute_group_id ) REFERENCES eav_attribute_group ( attribute_group_id ) ON DELETE CASCADEON UPDATE CASCADE ;

I know that a while ago I changed the 2 creation statements of the table to add the constraints on that place.

Does anybody has seen this before?

21 Dec 2010, 5:04 AM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: #1216 - Cannot add or update a child row: a foreign key constraint fails

Did you create your backup using the proper settings?
https://www.zen-cart.com/tutorials/index.php?article=103

Zen-Venom Get Bitten

21 Dec 2010, 5:23 AM
#3
cogmios avatar

cogmios

New Zenner

Join Date:
Jan 2008
Posts:
9
Plugin Contributions:
0

Re: #1216 - Cannot add or update a child row: a foreign key constraint fails

Yes, I did :smile:

I'm thinking what it was again, I thought it was a BUG in phpmyadmin, in the way it exports

But google on the error etc... does not give me anything.

It is simple what phpmyadmin does:

a) it creates the statement for the table
b) then inserts
c) and afterwards the foreign key constraints table alters

so some of the foreign key table alters will give this error, I thought I read about it somewhere on the mysql forums on the foreign keys.

So I would have expected to find it here on the forums en masse but searching via search does not give me anything on this.

21 Dec 2010, 5:35 AM
#4
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: #1216 - Cannot add or update a child row: a foreign key constraint fails

I havew not seen this in any ZenCart DB

Zen-Venom Get Bitten

21 Dec 2010, 5:54 AM
#5
cogmios avatar

cogmios

New Zenner

Join Date:
Jan 2008
Posts:
9
Plugin Contributions:
0

Re: #1216 - Cannot add or update a child row: a foreign key constraint fails

ah... I think I have exported the complete database... there is a lot more in there... I think I only need the tables with the zencart prefix...

anyway if you run into this problem : checking "disable foreign key constraints" while exporting might help.

21 Dec 2010, 5:58 AM
#6
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: #1216 - Cannot add or update a child row: a foreign key constraint fails

I think I only need the tables with the zencart prefix...

anyway if you run into this problem : checking "disable foreign key constraints" while exporting might help.
cogmios is online now Report Post Reply With Quote
And why I linked you to the proper settings for using phpmyadmin to create a proper backup

https://www.zen-cart.com/tutorials/index.php?article=103

Zen-Venom Get Bitten

21 Dec 2010, 6:11 AM
#7
cogmios avatar

cogmios

New Zenner

Join Date:
Jan 2008
Posts:
9
Plugin Contributions:
0

Re: #1216 - Cannot add or update a child row: a foreign key constraint fails

I think you should then update that instructions because....

the checkmark to not check for foreign key restrictions

... is NOT on that info page (!) :)

So... WHEN will that error occur?

ONLY when you have more than only ZEN in that same database and are restoring all of it. So it is basically an off-topic error for pure zen installations unless you have zen coupled with all other kinds of things and are running it from the same database.

21 Dec 2010, 6:19 AM
#8
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: #1216 - Cannot add or update a child row: a foreign key constraint fails

the checkmark to not check for foreign key restrictions

... is NOT on that info page (!) :)
I have not seen any phpmyadmin that checks it by default
Settings not mentioned can be left to their defaults

Zen-Venom Get Bitten

21 Dec 2010, 6:42 AM
#9
cogmios avatar

cogmios

New Zenner

Join Date:
Jan 2008
Posts:
9
Plugin Contributions:
0

Re: #1216 - Cannot add or update a child row: a foreign key constraint fails

kobra:

I have not seen any phpmyadmin that checks it by default

correct but IT MUST BE CHECKED so that it will not check for the foreign key constraints.