Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

primary key from GUID to integer Topic is solved

Questions related to using nuBuilder Forte.
Post Reply
homa
Posts: 3
Joined: Fri Sep 19, 2025 11:07 pm
Has thanked: 1 time

primary key from GUID to integer

Post by homa »

How can I change the primary key from GUID to integer with an auto-increment function? For individual tables, I would simply like to have the following: 1, 2, 3, 4, 5, ...
Ideally, I would also like it to be displayed in this form.
I hope there is a solution to this. Many thanks in advance.
kev1n
nuBuilder Team
Posts: 4487
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 507 times
Contact:

Re: primary key from GUID to integer

Post by kev1n »

Hi,

Open phpMyAdmin and follow the steps below. Replace with your table name and column names.

Step 1: Add the new INT column with AUTO_INCREMENT

Code: Select all

ALTER TABLE your_table ADD COLUMN id INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST;
Step 2: Drop the old GUID primary key

Code: Select all

ALTER TABLE your_table DROP PRIMARY KEY;
Step 3: Make the new column the primary key

Code: Select all

ALTER TABLE your_table ADD PRIMARY KEY (id);
Step 4: (Optional) Remove GUID column if no longer needed

Code: Select all

ALTER TABLE your_table DROP COLUMN guid;
homa
Posts: 3
Joined: Fri Sep 19, 2025 11:07 pm
Has thanked: 1 time

Re: primary key from GUID to integer

Post by homa »

Unfortunately, it's not that simple.
Creating with ‘Fast Form’ creates a primary key (anrede_id_tmp).
With your suggestion, SQL reports:
#1075 - Incorrect table definition. There can only be one AUTO_INCREMENT column, and it must be defined as a key.
Then I did the following:

Code: Select all

ALTER TABLE anrede DROP PRIMARY KEY;
ALTER TABLE anrede DROP COLUMN anrede_id_tmp;
ALTER TABLE anrede ADD COLUMN anrede_id INT UNSIGNED;
ALTER TABLE title MODIFY title_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY;
Now the following error message appears when attempting to enter data:
2025-09-20 18_38_39-nuBuilder - Fast Form 2 – Mozilla Firefox.png
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4487
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 507 times
Contact:

Re: primary key from GUID to integer

Post by kev1n »

You also need to change the PK in the form properties (ctrl + shift + f).
homa
Posts: 3
Joined: Fri Sep 19, 2025 11:07 pm
Has thanked: 1 time

Re: primary key from GUID to integer

Post by homa »

Okay, that worked!

Sorry for all the questions, but as a beginner, I need to understand the whole concept first. The more I discover, the more excited I get!
I've been looking for something like this for years. I only became aware of nuBuilder through a comment in a forum.

I'm struggling with SELECT in FORM. If I set the validation to 'No Blanks' under 'OBJECTS' Properties, why does the option to select 'NULL' appear in the drop-down menu? Is this a bug?
2025-09-20 21_54_00-nuBuilder - Fast Form 1 – Mozilla Firefox.png
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4487
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 507 times
Contact:

Re: primary key from GUID to integer

Post by kev1n »

Actually, the first option just has an empty value, which is the default.
Technically it isn’t required, so if you’d prefer to remove it you can do so with:

if (nuIsNewRecord()) nuSelectRemoveEmpty('insert_your_object_id_here',-1);
(Add JS in form's Custom Code)
Post Reply