SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2006
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    I have a shopping cart and am trying to do a fresh install of it while preserving the existing data in the database. So I installed the new version of the cart in a separate folder with a new database. I then followed the instructions below:

    1. select the new database
    2. go to tab "structure"
    3. check all tables
    4. "with selected" -> empty

    Rather that exporting and importing it could be worth a try to copy the old data into the new database
    (it assumes they run on the same server)
    1. select the old database
    2. go to tab "operations"
    3. copy database to -> "livecart_new" (name of the new database you have already created)
    - select "data only"
    It should now copy the old data into the new database.

    I was able to successfully empty all the tables of the fresh install, but ran into this when I tried to copy the data from the old database into the new empty database:

    Error
    SQL query: DocumentationEdit

    INSERT INTO `robertco_LC131`.`AccessControlAssociation`
    SELECT *
    FROM `robertco_LC`.`AccessControlAssociation`

    MySQL said: Documentation
    #1452 - Cannot add or update a child row: a foreign key constraint fails (`robertco_LC131/AccessControlAssociation`, CONSTRAINT `UserGroup_AccessControlAssociation` FOREIGN KEY (`userGroupID`) REFERENCES `UserGroup` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE)


    Can anyone assist me with this error? How come I simply can't copy data from old to new?

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,398
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    First copy the data in the UserGroup table

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2006
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see, so it can't just do a bulk copy from one database to the other? I have to figure out how to copy just the data then from that table in the old to the same in the new database...

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,398
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    If you have foreign key constraints, the tables have to be loaded in a certain order. Otherwise, the constraint will fail since the values are not present yet in the other table.

  5. #5
    SitePoint Evangelist
    Join Date
    Feb 2006
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand the meaning of the error now. Is there a simple way, or actual command that will copy the data from the tables in the order they need to go into the new database?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •