How can I add "AUTO_INCREMENT" for a field?

[expired user #2046]'s profile image [expired user #2046] posted 17 years ago in General Permalink
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?
[expired user #2046]'s profile image [expired user #2046] posted 17 years ago Permalink

*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
[expired user #1821]'s profile image [expired user #1821] posted 17 years ago Permalink


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.
[expired user #2714]'s profile image [expired user #2714] posted 17 years ago Permalink
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's profile image ansgar posted 17 years ago Permalink
Just click on the "Manage Indexes" button with the flash on it (left to the field list)
[expired user #2714]'s profile image [expired user #2714] posted 17 years ago Permalink

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's profile image ansgar posted 17 years ago Permalink

:) 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.
[expired user #2714]'s profile image [expired user #2714] posted 17 years ago Permalink

:) 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's profile image ansgar posted 17 years ago Permalink

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's profile image ansgar posted 17 years ago Permalink
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.