Title: Re-keying a database table
Last modified: October 25, 2019

---

# Re-keying a database table

 *  [judah75](https://wordpress.org/support/users/judah75/)
 * (@judah75)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/re-keying-a-database-table/)
 * Somehow my wp_postmeta table lost its primary key and auto-increment some time
   in the past. The table now has a giant stack of meta_id entries set to 0. Is 
   there a way to change their meta_id value so I can re-key the table and set it
   to auto-increment again?
 * Thank you,
 * Judah
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fre-keying-a-database-table%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [6 years, 6 months ago](https://wordpress.org/support/topic/re-keying-a-database-table/#post-12065370)
 * Nothing that you’d do inside WordPress. You’d have to fix this up via SQL coding
   and detective work. Does the problem go too far back to consider restoring the
   database from a backup?
 *  Thread Starter [judah75](https://wordpress.org/support/users/judah75/)
 * (@judah75)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/re-keying-a-database-table/#post-12066128)
 * Thank you for your reply, Steve. I was in myphpadmin when I found all of the 
   meta_id entries. At this point, I think this may be easier than trying to go 
   to a backup.
 *  Thread Starter [judah75](https://wordpress.org/support/users/judah75/)
 * (@judah75)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/re-keying-a-database-table/#post-12066625)
 * So, anyone know of a way to (a) change the meta_id of a row if the current meta_id
   is 0, (b) save all rows with a meta_id of 0 and re-enter them with a new meta_id
   value so that the originals can be deleted?
 * Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Re-keying a database table’ is closed to new replies.

## Tags

 * [auto-increment](https://wordpress.org/support/topic-tag/auto-increment/)
 * [phpmyadmin](https://wordpress.org/support/topic-tag/phpmyadmin/)
 * [primary key](https://wordpress.org/support/topic-tag/primary-key/)
 * [table](https://wordpress.org/support/topic-tag/table/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [judah75](https://wordpress.org/support/users/judah75/)
 * Last activity: [6 years, 6 months ago](https://wordpress.org/support/topic/re-keying-a-database-table/#post-12066625)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
