Fixing MySQL #1062 Error

by pvijeh
5 replies
Warriors-

I am trying to copy a development copy of my site to my production server- however when i try to upload my SQL database I get the following error

#1062 - Duplicate entry '153' for key 'id'


has anyone encountered this before?

Im not sure where else to turn

thanks

Peter
##1062 #error #fixing #mysql
  • Profile picture of the author Immu
    Reset identity to 154
    it will fix it

    Cheers
    {{ DiscussionBoard.errors[8766728].message }}
  • Profile picture of the author chrisranjana.com
    Originally Posted by pvijeh View Post

    Warriors-

    I am trying to copy a development copy of my site to my production server- however when i try to upload my SQL database I get the following error

    #1062 - Duplicate entry '153' for key 'id'


    has anyone encountered this before?

    Im not sure where else to turn

    thanks

    Peter
    Try emptying your current database fully before starting the dbimport once again. Do make a complete backup of your existing database before even thinking about deleting it though !
    Signature

    Chris, Developer, Chrisranjana.com,
    AWS Developer GCP Engineer Python NodeJS Programmer

    {{ DiscussionBoard.errors[8769751].message }}
    • Profile picture of the author tanmay92
      no need to delete. Changing it to 154 will resolve it :/
      {{ DiscussionBoard.errors[8772144].message }}
      • Profile picture of the author softwarewarden
        Originally Posted by tanmay92 View Post

        no need to delete. Changing it to 154 will resolve it :/
        not if theres something with id = 154 already they will get the error again for 154 instead of 153

        so you would need to backup, delete old data, the do the dbimport
        {{ DiscussionBoard.errors[8780481].message }}
  • Profile picture of the author shahriyar
    Originally Posted by pvijeh View Post

    Warriors-

    I am trying to copy a development copy of my site to my production server- however when i try to upload my SQL database I get the following error

    #1062 - Duplicate entry '153' for key 'id'


    has anyone encountered this before?

    Im not sure where else to turn

    thanks

    Peter
    The "id" field is your primary key (I believe) and its value is always unique (no dupe) to identify a record uniquely. The error is saying that there is a row with id "153" already and you are trying to add another row with id 153, hence the error.

    Is possible that the table already has a row with id 153? in that case you need update your source SQL (remove conflicting ids, replace them with unique values) before importing it to the new DB. Or clear the new table and try importing the SQL again.
    {{ DiscussionBoard.errors[8780836].message }}

Trending Topics