Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7985533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:35:01+00:00 2026-06-04T11:35:01+00:00

So i just truncated my table but now my primary key will not auto

  • 0

So i just truncated my table but now my primary key will not auto increment. Every time I add a 2nd item to the table, it comes back with 1062: Duplicate entry ‘0’ for key ‘PRIMARY’

I thought when you truncate a table it will just resets the auto increment back to 1.

I search around on what I could do but I have come across many people saying just truncate.

What I did

"TRUNCATE TABLE mytable;"

I must have done something wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:35:02+00:00Added an answer on June 4, 2026 at 11:35 am

    This bug not affects Mysql 5.0 and it is repeatable on 6.0 and 5.1.23 and 5.1BK.

    Refer this link for proof

    Following is readily available and effective workaround is to ALTER the autoinc value after the table is truncated.

    Re-initialize the autoinc value right after truncation

    alter table tablename AUTO_INCREMENT = n; /* set n as desired */

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering how I can make my app open automatically at login, but make
Just wondering if the following is considered to be good programming practice or not?
Similar to this question but for MySQL.... How can I programmatically determine foreign key
Seems like manage.py test creates test database every time I run the test. Is
I just ran truncate statement on a table and committed. What options do I
I've got a table with a lot (>20.000) records. It's time to clean those
Just to make sure I'm understanding shallow copies of reference types correctly and that
Just switched over from eclipse to vs 2008 for debugging javascript, i feel more
Just trying to get diff to work better for certain kinds of documents. With
Just looking for a good PHP Image Library, I want to display images with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.