distal-attribute
distal-attribute
distal-attribute
distal-attribute

How can I add "AUTO_INCREMENT" for a field?

johnnylee194 posted 10 years ago in General
I was trying to add the "AUTO_INCREMENT" property to a filed.

But I found that if I used "create field...", the check-box of the AutoIncrement is un-available.


If I create a filed, then try to add the property by "edit field...", then I will be prompt that the default value is invalid.


How can I solve this problem?
johnnylee194 posted 10 years ago

*snip*
If I create a filed, then try to add the property by "edit field...", then I will be prompt that the default value is invalid.
*snip*



For the second issue, if i remove the default value, it will be OK.

like this:
ALTER TABLE `recipes` CHANGE `id` `id` INT(32) UNSIGNED AUTO_INCREMENT
siMKin posted 10 years ago


I found that if I used "create field...", the check-box of the AutoIncrement is un-available.


An auto_increment field needs to be defined as a key. So, first you have to create the field, then define it as your primary key and then you can set it to auto_increment

If I create a filed, then try to add the property by "edit field...", then I will be prompt that the default value is invalid.
How can I solve this problem?


For the second issue, if i remove the default value, it will be OK.

like this:
ALTER TABLE `recipes` CHANGE `id` `id` INT(32) UNSIGNED AUTO_INCREMENT



You must have (accidentally) defined is as your primary key as well, otherwise that query wouldn't work.
trudge posted 10 years ago
You must have (accidentally) defined is as your primary key as well, otherwise that query wouldn't work.[/quote]

Can someone explain how to make a field a primary key please? Ive searched and found no definitive answers, yet you refer to creating one.
Many thanks.
ansgar posted 10 years ago
Just click on the "Manage Indexes" button with the flash on it (left to the field list)
trudge posted 10 years ago

Just click on the "Manage Indexes" button with the flash on it (left to the field list)



smileI saw that but thought it was for an index, not a primary key. Am I missing something here? They are different.

In any case I did manage to get my field defined as a primary key. I had to drop the table first, then in my SQL import script, add the proper command to make my field a primary key and auto_increment.

But it does seem strange that Heidi doesn't have a feature to alter a field dynamically. I'm coming from a phpMySQL GUI so this is a little different. But I definitely like it a lot.
ansgar posted 10 years ago

:) I saw that but thought it was for an index, not a primary key. Am I missing something here? They are different.



A primary key can be seen as an index, so the index editor has these tasks gathered.
trudge posted 10 years ago

:) I saw that but thought it was for an index, not a primary key. Am I missing something here? They are different.



A primary key can be seen as an index, so the index editor has these tasks gathered.



Ah. Thank you. I see that 'Primary Key' is now an option in the select list for managing indexes (indices?).

btw, any idea why my sig is not being attached. I have it set ON in my profile.
ansgar posted 10 years ago

Ah. Thank you. I see that 'Primary Key' is now an option in the select list for managing indexes (indices?).



Hehe. I'm nearly sure that it's "indexes", not "indices". I looked it up some time.

btw, any idea why my sig is not being attached. I have it set ON in my profile.



I disabled displaying signatures due to spamming problems. Sorry for any inconveniance.
ansgar posted 10 years ago
Revision 629 displays both tabs "field editor" and "index editor" at the same time.

http://svn.sourceforge.net/heidisql/?rev=629&view=rev

Please login to leave a reply, or register at first.