Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8529783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:06:29+00:00 2026-06-11T09:06:29+00:00

I am developing a tool to merge two databases with the same schema but

  • 0

I am developing a tool to merge two databases with the same schema but different data.

Part of it is changing all foreign keys to ON UPDATE CASCADE, then incrementing all the Primary Keys to avoid conflicts and keep foreign keys pointers working.

My problem is that sometimes there are some orphaned rows with broken FK, so following query:

UPDATE table set pk = pk + 1000000

fails like this:
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails…
(despite I’m not even thinking about touching foreign key column!)

I wanted to turn that off by:

Set foreign_key_checks=0

but then related foreign keys are not updated. I’ve made a quick test and cascades are not working after setting foreign_key_checks=0.

Is there any way to trigger cascades, or perform an update of a row with broken FK without setting foreign_key_checks=0? UPDATE IGNORE doesn’t solve this problem 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:06:30+00:00Added an answer on June 11, 2026 at 9:06 am

    You should first fix referential integrity.

    1. Delete orphan rows if the relation is a composition type
    2. update the fk field to null otherwise

    After that your operations will work just fine.

    Additional information:

    If the column is NOT NULL, it means this the relation is a 1*. In this case, you have to add a virtual row in the parent table (say, “VIRTUAL PARENT” row) and update all fks pointing to an unexisting parent to this one. This will allow you later to proceed the datas and moreover to retrieve them easily.

    If you think the 1* is not necessary (0* would be enough for your technical / applicative layer) then just set the column as nullable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a tool to dump data from variables. I need to dump
I am developing a PHP web based data entry tool with MySQL as the
I am developing a tool where lots of data (>1MB of data) with lots
I have multiple Ecore files for different purposes. I am now developing a tool
I need a tool to manage a project that I developing, but I don't
I'm developing web application on python. But the client wants a tool that exports
I'm developing a tool which shows data from a database in a hierarchical manner.
I am developing a simple tool that will be used across a variety of
I'm developing a TFS tool to assist the developers in our company. This said
I'm developing a Zoom tool in my Flex App, so I'm using scaleX and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.