zeoforce
Joined: 20 Aug 2008
Posts: 1
Location: Illinois
|
| Posted: Wed Aug 20, 2008 5:43 pm Post subject: MySQL error: Duplicate entry '0' for key 1 after db restore |
|
|
I was getting this error after switching vTiger to a new host. It turns out that using phpMyAdmin to do the export was a bad idea. None of the auto_increment fields were in place. I saw a few others had this issue and thought I would present my solution to it...
On the old server, I ran these queries (has to be MySql 5, these don't work in version 4; also note: you will need at least select access to the information_schema tables used in these queries):
select concat('alter table ', table_name, ' CHANGE ', column_name, ' ', column_name, ' ', column_type, ' NOT NULL AUTO_INCREMENT;') from information_schema.columns where table_schema='vtigercrm' and extra='auto_increment';
and then
select concat('ALTER TABLE ', table_name, ' AUTO_INCREMENT=', AUTO_INCREMENT, ';') FROM information_schema.tables WHERE TABLE_SCHEMA='vtigercrm' and auto_increment is not null;
be sure to change the table_schema from 'vtigercrm' to whatever your database is named. Simply run the output of these 2 queries on the new database right after doing your import and you shold be good to go!
The first query will produce a list of queries to re-enable all of the auto_increments on all of the tables. The second query outputs the correct auto_increment values so they are all up to date. |
|