Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export and import data from PHPMYADMIN

I exported data with phpMyAdmin, but when I import the data I get this error:

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

I can set the data accordingly and then I don't get the error. But is there a better way to do this? Something like disabling some options in phpMyAdmin or adding some query to SQL?

like image 834
Luciano Gretgerd Avatar asked Jul 13 '12 10:07

Luciano Gretgerd


People also ask

What is the purpose of import and export in phpMyAdmin?

This allows the 'auto_increment' field to populate correctly. It is now possible to import a CSV file at the server or database level. Instead of having to create a table to import the CSV file into, a best-fit structure will be determined for you and the data imported into it, instead.


1 Answers

The problem is pma doesnt care about the order for the insert rows. so it happens a table-row is inserted with an FK where the FK row is not yet imported.

To solve this use the checkbox Disable Foreign Key Checks when exporting from PhpMyadmin. Or set it yourself:

SET FOREIGN_KEY_CHECKS=0;

and at the end:

SET FOREIGN_KEY_CHECKS=1;
like image 150
Rufinus Avatar answered Oct 24 '22 10:10

Rufinus