Duplicate entry key on import - mysql

We’re facing a few problems when trying to update product in Magento at the moment.
What we’ve done so far to eliminate any problems:
Wiped all products from the database
Imported all products
Everything was working on site great, then we’ve seen something that needs updating in all of our products so we’re trying to re-import our products to update the existing products.
This is where we’re experiencing some issues:
Importing existing product with an update produces error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-0-1' for key 'PRIMARY'
This happens on the first record it process
Does anyone have any ideas on why this is happening? what it the error message actually saying?

How are you updating the products? Are you using the product import or dataflow? There is a primary key(s) on the table. The manner in which you are doing the import is trying to add the products and not update them. Since the primary key must be unique, you are trying to put a new record in with an existing primary key. That's what the SQL error is...
Go into the Magento admin, under System > Import/Export > Export. That will get you all the data in the correct format. Make your changes. Then go back and do an import.
On the import screen select 'Replace Complex Data' as the import behavior. I would backup the database first and test it out on a dev environment, but that is the correct way to handle it.

Related

How do I avoid foreign key constraint fail error -

I am currently using dreamweaver and I am trying to insert a record insertion wizard connected to a mysql server. However when I try to update the column I get a foreign key constraint fail and I can understand this is due to me creating a non existent foreign key.But how else can I use an input wizard.
database
Here is the data model.
The column I am trying to update is "kommentar" but it is not working, any ideas?
Tough to say with the info provided, but in all likelihood the value you're using in hotellid doesn't have a corresponding entry in the table hotell.
You could run the same wizard for the hotels and add a hotel with your desired hotelid, before inserting into kommentar

Integrity error django

I was using sqlite3 for my database in django project and then I decided to change it to mysql engine. I changed everything in the settings.py correctly, and in order not to lose the db I dumped my sqlite one to text and I changed every " with `, removed Commit and all things related to sqlite3. I executed the dump file on mysql and everything was added perfectly. However, when I try to add a cateogory in a table called categories.
I get this error message
IntegrityError at /admin/red_carpet/category/
(1062, "Duplicate entry '0' for key 1")
I thought the key is duplicate wich what is the error saying. I looked at the "id" column to see it is structure I found that the id column is "NOT NULL". There was no auto increment added to that column so I added it and tried to do category from admin page I got the same error I looked again at the structure and then I added the query that the auto_increment shouldn't start from 0 but should start from last value which was 6. Then I added the category from the django admin again but I still get the same error, looked again at the structure and especially in the indexes part in phpmyadmin I found that line
Keyname Type Cardinality Action Field
PRIMARY PRIMARY 9 id
For me, everything looks good and actually when I add value through django admin I get it added though I get the same error message
IntegrityError at /admin/red_carpet/category/
(1062, "Duplicate entry '0' for key 1")
I really can't understand why is this problem !!!! Anyone have been thorough this before !! ??
PS: I get the same error message when I try to remove something. For example, if I am removing a cateogory I get the exat error message though when I look at the db I found that the category has been removed !!
One way to prevent cross-db issues would be to use fixtures, e.g. dump and load your data in (db-agnostic) json format:
see dump data command and
what is a fixture
from the django documentation.

Importing SQL file "Duplicate entry '0' for key 'PRIMARY'"

I know there is similar questions that are answered but please try to help me out.
I'm importing a backup of my MyBB database into a new host using PHPMyAdmin. When trying to import the .sql file, I get the following error:
SQL query:
INSERT INTO mybb_datacache( `title` , `cache` )
VALUES (
'internal_settings', 'a:1:{s:14:\"encryption_key\";s:32:\"rrvohvVATtOauucNTmEXAmvNvbw9ujvb\";}'
);
MySQL said:
#1062 - Duplicate entry 'internal_settings' for key 'PRIMARY'
I can't figure out the problem. I emptied all tables and clean install of the database four times already. I've been trying to figure this out all day and it's very frustrating.
(link removed)
Please help me out. How do I fix this problem?
When you export your sql from php admin
Select "custom" as export method"
then, instead of 'insert', choose "update"
This will perform update-statements and prevent duplicated inserts.
Make sure the column set as your PRIMARY KEY is set to AUTO_INCREMENT
From the current version of the question, it appears that the title column of the mybb_datacache table is the Primary Key and already has a record with the value 'internal_settings' in it. If this is indeed the case, then the problem is that all records must have unique values for their Primary Key.
I had this problem, and i found what the problem is.
The thing is that, the field cannot be empty. ie, if you are altering a table to add primary key, make sure you have some values in that field. or if u are importing a sql file, make sure that that field in the file has some values....
this solved my problem...

magento can't reindex product attributes

When I run Reindex from Index Management it gives error "Cannot initialize the indexer process."
So based on following article here
http://jasonehmke.com/ecommerce/cannot-initialize-the-indexer-process-in-magento/
I ran
php -f indexer.php reindexall
Which gave following output:
Product Prices index was rebuilt successfully
Catalog URL Rewrites index was rebuilt successfully
Product Flat Data index was rebuilt successfully
Category Flat Data index was rebuilt successfully
Category Products index was rebuilt successfully
Catalog Search Index index was rebuilt successfully
Stock Status index was rebuilt successfully
Tag Aggregation Data index was rebuilt successfully
Product Attributes index process unknown error:
exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '65-542-1-65' for key 'PRIMARY'' in /home/bizzosph/public_html/lib/Zend/Db/Statement/Pdo.php:228
Next exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '65-542-1-65' for key 'PRIMARY'' in /home/bizzosph/public_html/lib/Zend/Db/Statement/Pdo.php:234
Any idea how do I fix this? It does not tell me what table has duplicate entry.
Thanks
I'm sure you've moved on since posting this question, but since it has ~2500 views (and having this answer here would have helped me), I'll add the resolution I found. This does not require truncating any database tables or even any direct SQL queries:
Last night, I was having the same problem. My error was the same as yours (except for the numbers which refer to the product and attribute causing the problem). If you go and re-save that product in the Manage Products section of the admin (no need to change it, just open it to edit and click save), it will solve the problem - but you very likely have more products that will bring additional similar errors.
In my case, it wasn't just a problem with 1 product there were several hundred products causing errors (each one saved brought up a new one). And it wasn't all with the same attribute (I'd updated multiple attributes across a database of over 4,000 products in my last import).
Since everything seemed to actually be in the database correctly (since re-saving seemed to be fixing it and giving the proper data to the final saved product), I had an idea.
Why not export all 4k products, and then re-import the same file without modification and see if that clears it.
It worked!
tl;dr: If you're having this problem with multiple products needing to be re-saved, export your whole inventory (or the relevant section if you can segment in a useful way), and re-import the same file with no modifications.
I'm using Magento v 1.9.0.1
Try first to clean Magento cache. If no success, run official DB repair tool
The solution is to run the following MySQL queries:
TRUNCATE TABLE `catalog_product_flat_1`;
TRUNCATE TABLE `catalog_product_flat_2`;
TRUNCATE TABLE `catalog_product_flat_3`;

MySQL Error: #1062 - Duplicate entry 'rewrite_rules' for key 2

I am trying to restore a WordPress MySQL DB from a recent backup since my site (wp-admin) became unusable after I changed the site_url incorrectly. I am trying to reinstall the entire site again but need to reinstall the DB. The problem is my wp_options table will not upload via PHPmyAdmin. The error I get is:
#1062 - Duplicate entry 'rewrite_rules' for key 2
I know little about MySQL but this seems odd as the DB was working happily before I deleted it to attempt the reinstall.
Can anyone please advise?
The error means that you are inserting data into a column with must be unique.
In this case you may be importing data that has 'rewrite_rules' as a data item in a row into a table that already has 'rewrite_rules' as a data item in a row in a column that as been marked as unique.
If you are reinstalling wordpress from scratch and are trying to import the old data over the top you need to take a few steps first. See the link below for some instructions
http://www.ehow.com/how_4579080_export-import-wordpress-blog.html