Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 6th, 2005, 01:32 PM
Registered User
 
Join Date: Jul 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Auto_incremente

Hi! i have a table called Estados and row called EstadoID (int), Description (varchar)

it has 3 records loaded. Now i want to make it auto_increment (EstadoID) because it wasn´t but i receive the error duplicate entry key. How can i make it auto_increment without the need to delete records or updating them (because they are foreigns keys). The problem it´s that i forgot to tell mysql that EstadoID was auto_increment
Thanks in advance. Guillermo.

 
Old July 6th, 2005, 01:47 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Guillermo,

Something like this should do it...
Code:
ALTER TABLE Estados MODIFY COLUMN EstadoID INT AUTO_INCREMENT;
HTH,

Chris

 
Old July 7th, 2005, 08:22 AM
Registered User
 
Join Date: Jul 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No.... mysql says
Duplicate entry '1' for key 1

This is the content of Estados table

Descripcion EstadoID Imagen
RESERVADO 0 98148-750098490_cartel_raulMel.jpg
Sin Estado 1 59259-685750268_notavailable.JPG
Vendida 2 90741-685750269_notavailable.JPG


 
Old July 7th, 2005, 08:42 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

You should not have a zero value in an AUTO INCREMENT column.










Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.