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 8030719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:51:37+00:00 2026-06-05T00:51:37+00:00

I am trying to insert an element in a table where there are already

  • 0

I am trying to insert an element in a table where there are already 3 rows.

Its a table called usuarios=[id (primary, autoincrement), fid, first_name, last_name....]

So there are already 3 rows with id’s: 0,1,2

And when I am trying to execute this query (note I am not setting value for id attribute)

INSERT INTO usuarios (fid,email,pass,first_name,last_name,avatar,bday,fecha,id_loc,id_loc_from) 
       VALUES       (-1,'toni@ideadeia.com','72253f579e7dc003da754dad4bd403a6','','','',NOW(),NOW(),'','')

I get this mysql error:

Duplicate entry '0' for key 1

extra: I don’t know how this 3 items where inserted (if via interface, by console query, ..)

So question is, how can I make sure that the Primary Keyis autoincrement, and if not; how to set it? (will that solve the problem?)

  • 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-05T00:51:39+00:00Added an answer on June 5, 2026 at 12:51 am

    You should be able to set it as auto-increment using this statement if you have rights to alter the table:

    ALTER TABLE usuarios  modify id INT(11) NOT NULL AUTO_INCREMENT;
    

    Although I’ve seen reports of bugs that recommend instead dropping the colulmn and recreating it, if the above doesn’t work for some reason. the syntax recommended in those posts is:

    ALTER TABLE usuarios  
             DROP COLUMN id;
    
    ALTER TABLE usuarios  
             ADD COLUMN idINT(11) NOT NULL AUTO_INCREMENT FIRST;
    

    Warning: Do this in a test database first. You’d want to be careful doing this if the table is using this as a foreign key. It could fail at best, or break all the relationships at worst.

    There’s tons of info at the MySql reference manual.

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

Sidebar

Related Questions

I'm trying to use jQuery to insert HTML into a table element. I've been
I am trying to insert rows into an html table with javascript. I have
I'm trying to write a program in Prolog, which will insert an element into
I'm trying to run .ajax and insert a data element from the onClick of
I am trying to insert data in MySQL using Python. There is an error
I am trying to insert a ul li element inside a tab structure. Am
I'm trying to insert an li element into a specific index on a ul
I'm trying to insert a panel into a wxBoxSizer before the last element in
Using Prototype 1.6's new Element(...) I am trying to create a <table> element with
I'm trying to insert an element node (that has some children) from one XML

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.