Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

auto_increment x primary key

Post Reply
rradunz
Posts: 6
Joined: Fri Mar 29, 2013 11:14 pm

auto_increment x primary key

Unread post by rradunz »

Just wanted to post this to help other newbies like me, regarding the primary key usage.
Please correct me if I am wrong.

Not sure the tutorials or the forum mention this, but for me it was not clear at first that auto_increment was not recommended, and, worst, that if you include the primary key name in the field list (browse) or in object list you would have a problem.

It was when I get the error #1062 - Duplicate entry for key 'PRIMARY' that I was aware of the issue. I was surprised because the key (4) was there, and there was no duplicates; but looking again In the statement below:
UPDATE sea_depositos SET dep_bairro = 'c', dep_CEP = '', dep_cidade = '', dep_contato = '', dep_endereco = '', dep_estado = '', dep_id = '', dep_lat = '', dep_lon = '', dep_nome = '', dep_telefone = '' WHERE dep_id = '4'

you see that the primary key field is included in the update making MySQL issue the error. Remove that part and you are good.

To fix it, you go and remove any references to the primary key field in the form (browse) and object lists.

so, as far as I know now, you can use auto_increment and numeric keys, subject to other issues as posted in this forum, or follow the recommendation to use VARCHAR(15) and no auto increment, and DO NOT include the primary key field name in the field lists.

Thanks for this great free software, and please correct/complete this post if needed.

RR
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: auto_increment x primary key

Unread post by admin »

RR,

I'll update the wiki to mention these 2 things.

Allowing for auto-incrementing primary keys was a late addition to nuBuilder to cater for people importing their current data.

Steven
Post Reply