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

  • Home
  • SEARCH
  • 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 6753261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:08:22+00:00 2026-05-26T13:08:22+00:00

I am trying to restore a DB using an SQL script, but things foreign

  • 0

I am trying to restore a DB using an SQL script, but things foreign key constraints get in the way

I am taking a MySQL DB and bringing it over to PostgreSQL.
Since the MySQL create table syntax ended up being quite different, I took another PostgreSQL DB with the same schema, but different data and restored the schema only, from that.
In other words, I now have a database with tables, constraints, sequences and all that shnaz but no data inside.

So, it’s is time to restore data.
I take a backup of the MySQL DB with phpMyAdmin (data only) as an SQL script (pgAdmin does not seem to accept zip or gzip files for some reason) and run the SQL script.
Now, this is where the problems start to happen, it’s only natural, I am going from MySQL to PostgreSQL, so syntax errors are bound to happen.

But, there are other non syntax related problems to, like this one:

ERROR: insert or update on table "_account" violates foreign key constraint "fk_1_account"
DETAIL:  Key (accountid)=(2) is not present in table "_entity".

So, yeah, basically, a foreign constraint exists, the query is trying to insert data into the _account table, but the corresponding data has not been inserted into the _entity table yet.
How do I get around that? Is there a way to make pgAdmin3/PostgreSQL disable ALL OF the constraints, insert the data, and then re-enable the constraints?

A syntax related error I encountered, was this one:

 INSERT INTO _accounttype_seq (id) VALUES (11);

The PostgreSQL equivalent of that statement (if I am correct) is

 ALTER SEQUENCE _accounttype_seq INCREMENT BY 11; 

But, it’s a bit of a pain to run through the whole script and change all 200+ Sequence insert statements. So, I am being lazy here, but is there an easier way to deal with the sequences as well?

Or, do you guys have any suggestions for a different set of tools to make this easier?

Thanks for your time, have a good day.

  • 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-05-26T13:08:22+00:00Added an answer on May 26, 2026 at 1:08 pm

    Do not try to get around the foreign key constraints. That is the way to make sure the data is bad.

    First look at the constraints and make sure you are inserting to the tables in the correct order. If _entity is parent of “_account, then it should be populated first.

    Next you need to have the script move any failing records to an exception table. Then you can look at them and see what the data integrity issues is and if you need to throw the records away permanently or try to figure out what the missing parent value should be. If it is critical data such as orders where the customer no longer exists (possible in any system that didn’t have correct fks to begin with) and you must keep the record and cannot determine what the parent value should have been, you can create an ‘Unknown” record in the customer table and assign all bad orders to that customer id.

    And manually changing the alter sequences shouldn’t take long even if it is boring. There wil be plently of other things you need to handle manually in a conversion of this type.

    I would try to find a data import tool for PostgreSQL – I live in SQL server world where I would use SSIS but you need the equivalent of SSIS for the PostgreSQL world.

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

Sidebar

Related Questions

Instance A is trying to restore instance B's window, but I can't get the
I'm trying to figure out a way to restore (Put Back) Trash Item using
I am trying to restore MySQL database data from a dump file, using C#
I am trying to restore a database using mysqldump, but nothing seems to happen.
I am trying to restore the database file(backup.sql) using c# by the following method...
I was trying to restore a backup but I kept getting OS error 32
Trying to make a MySQL-based application support MS SQL, I ran into the following
I'm trying to automate svnadmin dump using C# ProcessStartInfo. The way I've done it
I am trying to archive my UIWebView object using NSKeyedArchiver and restore it later
I'm trying to restore a database by using the following code string Restore =

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.