Exported mysql WordPress database, then filled it back. Now nothing can be added to the postmeta table, issues: # 1062 - Duplicate entry '0' by key 'PRIMARY'

For example for this query: INSERT INTO fbi_postmeta ( meta_id , post_id , meta_key , meta_value ) VALUES ('', '0', 'test', 'test')

If you specify the meta_id manually, it works fine.

As far as I understand, when specifying meta_id = ", the value of meta_id is taken not from the last value in the table, but from 0.

How to make so that was taken from the last?

Table structure: Table structure

  • and AUTO_INCREMENT costs at meta_id? - user190134
  • Not. I tried "ALTER TABLE fbi_postmeta AUTO_INCREMENT = 555", but it doesn't work - Oleg
  • "Exported the mysql WordPress database, then poured it back." What for? You broke the base. And on the screen you have all the primary keys - do not you see? - SeVlad
  • Then what did backup. Since when should the preservation and restoration of the base break it? About all primary keys - in this table in other databases wordpress is also like this - Oleg

1 answer 1

The meta_id field on which the primary index is declared, this field itself must have an auto_increment attribute

  `meta_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT 

Otherwise, all added like this "INSERT INTO fbi_postmeta (meta_id, post_id, meta_key, meta_value) VALUES ('', '0', 'test', 'test')" records will receive a meta_id of 0 and everything will break on adding a second lines.