Page 1 of 1
primary key from GUID to integer
Posted: Sat Sep 20, 2025 12:42 pm
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.
Re: primary key from GUID to integer
Posted: Sat Sep 20, 2025 1:40 pm
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;
Re: primary key from GUID to integer
Posted: Sat Sep 20, 2025 6:44 pm
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
Re: primary key from GUID to integer
Posted: Sat Sep 20, 2025 7:14 pm
by kev1n
You also need to change the PK in the form properties (ctrl + shift + f).
Re: primary key from GUID to integer
Posted: Sat Sep 20, 2025 10:01 pm
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
Re: primary key from GUID to integer
Posted: Sun Sep 21, 2025 4:08 am
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)