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

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

Related

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

I am at a complete loss here. I have two databases. One on my localhost site that I use for development and one on my remote site that I use for my live (production) site. I manage both of them through phpMyadmin. As I have been doing for months now, when I need to update the live site, I dump the related database and import the database from my localhost site.
Now, no matter what I try, I keep getting this error:
Error
SQL query:
--
-- Dumping data for table `oc_address_type`
--
INSERT INTO `oc_address_type` ( `address_type_id` , `address_type_name` )
VALUES ( 1, 'Billing' ) , ( 2, 'Shipping' ) ;
MySQL said: Documentation
#1062 - Duplicate entry '1' for key 'PRIMARY'
I tried creating a new blank database on my localhost and importing into that but same results. I have validated all of the tables and indexes and cannot find anything wrong there.
Any suggestions please as I am completely down until this gets resolved.
By the way, I am completely dropping all tables and importing structure and data. This has always worked until today.
you need to dump with the drop statements. The table exists and has data already and your trying to insert more which is identical. Im not 100% sure on phpmyadmin but the dumps will have an option for "add drop table" statements
Dump your database on localhost with "mysqldump --insert-ignore ..." then try to import with phpmyadmin on your live machine.
Or try to connect to your live database with command line tools (configure your database to be able to connect from other hosts than "localhost" first!)
Then you can try following:
$ mysql -f -p < yourdump.sql
with -f "force" you can ignore errors during importing. It's the same as adding "--force" parameter to "mysqlimport".
The problem is related with your file - you are trying to create a DB using a copy - at the top of your file you will find something like this:
CREATE DATABASE IF NOT EXISTS *THE_NAME_OF_YOUR_DB* DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci; USE *THE_NAME_OF_YOUR_DB*;
and I'm sure that you already have a DB with this name - IN THE SAME SERVER - please check, because you are trying to overwrite!! Just change the name OR (better) ERASE THIS LINE!
For me the foreign_key_checks and truncate table options was useful.
SET foreign_key_checks = 0;
TRUNCATE `oc_address_type`;
SET foreign_key_checks = 1;
Run the above sql script, and after the import.
I had this same issue, my problem was I had a primary key column called unique_id and when you try to add two of the same value in that primary keyed column, it comes back with the error below.
A primary key column's data is all suppose to be different, so that bottom 1 I changed to 3 and the error went away.
Your MySql is not corrupt, like previous answers and comments.
you need to delete any previous tables that you are over-writing. if you are doing a complete restore of all tables, delete all existing tables.
I have met the same problem, I drop the table and rebuilt the database, then the problem solved.

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.

Magento re-index, cannot create table

I'm trying to re-index the category flat data, but I am always met with the same error:
There was a problem with reindexing process. Error Message: SQLSTATE[HY000]: General error: 1005 Can't create table 'xxx.catalog_category_flat_store_6' (errno: 121)
The table doesn't exist, there is a 1 and a 7. Not sure if that makes a difference?
After running the query manually through phpMyAdmin, I am met with the MySQL error 121. I've checked around and this would suggest the names of the foreign keys trying to be created already exist. I've listed all foreign keys in the DB right now, and they don't exist at all.
I've also tried running SHOW ENGINE INNODB STATUS on the DB for more information, but we don't have the rights to view that apparently.
After getting the priv's updated so we could run SHOW INNODB STATUS, we discovered that we already had an existing index that was attempting to be duplicated with this new table. This stemmed from us backing up an older version of the table that was trying to be created. Deleting that copy of the table enabled Magento to re-index properly and solved our problem.
Try logging the sql commands and debug what its trying to do by executing them manually. On the index process, normally there is a command that clears a table, and another to recreate it.
Edit /magentoRoot/lib/Varien/Db/Adapter/Pdo/Mysql.php and change $_debug to true and note the $_debugFile location (should be var/debug/pdo_mysql.log)
Its best to edit the file in vi, have a browser open to reindex JUST the category data, save the file in vi :w! and then run the indexer then change the debug back to false.
Then go read the log. It may help.

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`;

Duplicate entry key on import

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.