Jump to content

Exporting localhost database into a new database throws error!


n0sleeves
 Share

Recommended Posts

Okay, before I say anything, I know I should be using Git. Yes. It would make my life easier, but I really don't want to right now. Plus, I want to use a new database instead of messing up the original. So, with that said:

I have project 1 folder (contains active PW and site files). I exported the database and duplicated the folder. When I went to import the exported database into the newly created one, I get this error:

#1062 - Duplicate entry '2' for key 'PRIMARY'

Wtf? I thought it would be simple to just backup / import. Guess not :( I am not a SQL experienced user so I am lost. Tried googling but answers are too complicated. 

Help please  :rolleyes:

Link to comment
Share on other sites

How did you export the database? Give us a quick description of the steps you took to export & import, with any tools used.

Using Wamp and PhpMyAdmin (Version information: 4.0.4)

MySQL server (Server version: 5.6.12-log)

Here's the steps I do:

  1. Select project_v1 database (the original database). 
  2. Choose Export > Quick Export > SQL Format
  3. File saved
  1. Created a new database called project_v2, then select it
  2. Choose Import > I select previous exported file > Leave it on all default Settings

    Then this error pops up when I hit Go:

Error
SQL query:

--
-- Dumping data for table `fieldgroups`
--
INSERT INTO  `fieldgroups` (  `id` ,  `name` ) 
VALUES ( 2,  'admin' ) , ( 3,  'user' ) , ( 4,  'role' ) , ( 5,  'permission' ) , ( 1,  'home' ) , ( 88,  'sitemap' ) , ( 83,  'basic-page' ) , ( 80,  'search' ) , ( 97,  'album' ) , ( 98,  'artist' ) , ( 99,  'artists' ) , ( 100,  'track' ) , ( 101,  'catalog' ) , ( 102,  'genres' ) , ( 103,  'genre' ) , ( 104,  'moods' ) , ( 105,  'mood' ) , ( 106, 'full-width' ) ;

MySQL said: Documentation

#1062 - Duplicate entry '2' for key 'PRIMARY'
Link to comment
Share on other sites

What happens when you go to your new database in PHPMyAdmin, under the "Structure" tab and click "Check All" and change "with selected" to "Drop" and then press "Go", then try the database import again?

Link to comment
Share on other sites

It looks like you're importing your db after a new installation of processwire, which has just set some primary keys (ids) and so it gaves you an error when you're trying to overwrite them (at least I'm guessing so).

Try to import your db before installing pw, skip it and then try to go to yoururl/processwire (or any admin url you've set).

Just my two cents.

  • Like 2
Link to comment
Share on other sites

What happens when you go to your new database in PHPMyAdmin, under the "Structure" tab and click "Check All" and change "with selected" to "Drop" and then press "Go", then try the database import again?

The new database is empty and doesn't show that. 

It looks like you're importing your db after a new installation of processwire, which has just set some primary keys (ids) and so it gaves you an error when you're trying to overwrite them (at least I'm guessing so).

Try to import your db before installing pw, skip it and then try to go to yoururl/processwire (or any admin url you've set).

Just my two cents.

When I copied the project folder to a new folder, I also copied Processwire with it. No new installation.  

Link to comment
Share on other sites

Hmm, cstevensjr and 3fingers have covered exactly the ground likely to cause these issues.

Having googled around, and please forgive me for suggesting this, are you absolutely sure that you are importing the db structure into the new db and not the old one? The reason I ask is that that is one way to guarantee duplicate keys, because they would of course already exist. (And we do all do things like that occasionally.)

Link to comment
Share on other sites

Hmm, cstevensjr and 3fingers have covered exactly the ground likely to cause these issues.

Having googled around, and please forgive me for suggesting this, are you absolutely sure that you are importing the db structure into the new db and not the old one? The reason I ask is that that is one way to guarantee duplicate keys, because they would of course already exist. (And we do all do things like that occasionally.)

No offense taken. Yes, I am positive I am importing the old, exported, original database into the new, blank and empty db. I even created yet another db with a different name to see if that was the problem and still throwing the same error :/ 

Link to comment
Share on other sites

Not sure how it could possibly have happened, but have you checked through the SQL file to make sure that:

INSERT INTO `fieldgroups` ( `id` , `name` )

is not duplicated anywhere.

If by "not duplicated"  you mean (only showing once), then yes, it only appears once in the SQL file. 

Can you post the first page of the SQL you are trying to import

Sorry, my limited noob knowledge does not understand what constitutes pages :( I have one SQL file. Would you like to see the complete contents of it (it's pretty long)?

Link to comment
Share on other sites

Ok @n0sleeved, I think I got the solution ^-^

Here in my office I got your same setup and, following the exact same procedure you mention, I recieve the error MySql gave you.

To solve this I've choosen not to export through the "Rapid" option, and go for the "Custom" one. In the options panel I have then checked:

Add instruction DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT

and exported leaving all the rest with default values.

It worked!

Let us know!

  • Like 5
Link to comment
Share on other sites

Ok @n0sleeved, I think I got the solution ^-^

Here in my office I got your same setup and, following the exact same procedure you mention, I recieve the error MySql gave you.

To solve this I've choosen not to export through the "Rapid" option, and go for the "Custom" one. In the options panel I have then checked:

Add instruction DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT

and exported leaving all the rest with default values.

It worked!

Let us know!

That worked!!!!!!! OMG - THANK YOU @3fingers!  :biggrin:  :biggrin:  :biggrin: 

Thanks for all the other replies as well guys. It's so nice to have this forum where people are so willing to help each other. In all my experience using other "forums" across various websites, this one has proven to be the most helpful, friendly, and open. The fact, that we all use Processwire makes it even better. 

Now I can finally get back to working on this site.    

  • Like 1
Link to comment
Share on other sites

  • 9 years later...
On 6/5/2014 at 12:52 PM, 3fingers said:

Ok @n0sleeved, I think I got the solution ^-^

Here in my office I got your same setup and, following the exact same procedure you mention, I recieve the error MySql gave you.

To solve this I've choosen not to export through the "Rapid" option, and go for the "Custom" one. In the options panel I have then checked:

Add instruction DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT

and exported leaving all the rest with default values.

It worked!

Let us know!

your solve is still up to date! It save my time a lot!
Thx!
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...