I am trying to rework an old implementation of osCommerce and re-introduce data from the old database to the new one. I exported the data from the old tables using phpMyAdmin. When I tried to import them to the new database, I got a series of errors. I am simplifying the problem here to a single INSERT statement for the sake of clarity.
The statement is:
INSERT INTO `address_book` (`address_book_id`,
`customers_id`,
`entry_gender`,
`entry_company`,
`entry_firstname`,
`entry_lastname`,
`entry_street_address`,
`entry_suburb`,
`entry_postcode`,
`entry_city`,
`entry_state`,
`entry_country_id`,
`entry_zone_id`)
VALUES (1, 1, 'm', '', 'Mary', 'Smith',
'1234 Pleasant Court', '', '67890',
'Hometown', 'state', 123, 0);
When I try to import it from a file through phpMyAdmin I get an error: “#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1.”
If I click the Edit button and resubmit the query, I get another error: “#1062 - Duplicate entry '1' for key 'PRIMARY'.”
The address_book_id field is the primary key in this table and is an auto-increment field.
Still in the edit screen, if I change the address_book_id value to NULL and resubmit, the query is accepted.
Thinking I had the issue resolved, I changed the address_book_id value in the import file to NULL and tried importing again. And again, I get the #1064 error. I immediately clicked edit. I made no edits to the statement but submitted it without change. This time, the statement was accepted.
It appears to be a problem with handling the address_book_id value in the downloaded data. I have hundreds of index values from numerous tables from the old database. Obviously, I don’t want to have to change the index values and submit them one at a time.
I am working with phpMyAdmin 3.5.1. Any idea what is going on?
2
Answers
After playing around with this for a while, I think the best approach is to delete then recreate the tables. I tried this on two tables and was then able to upload my data, including the id fields without throwing any errors. The tables seem to be working OK.
Do it without the
address_book_id
. Apparently that one is the primary key which you can’t simply copy from another table. The new ID should be assigned automatically.