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.
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.
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
-
- 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
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
Step 2: Drop the old GUID primary key
Step 3: Make the new column the primary key
Step 4: (Optional) Remove GUID column if no longer needed
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;
Code: Select all
ALTER TABLE your_table DROP PRIMARY KEY;
Code: Select all
ALTER TABLE your_table ADD PRIMARY KEY (id);
Code: Select all
ALTER TABLE your_table DROP COLUMN guid;
Re: primary key from GUID to integer
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:
Now the following error message appears when attempting to enter data:
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;
You do not have the required permissions to view the files attached to this post.
-
- 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
You also need to change the PK in the form properties (ctrl + shift + f).
Re: primary key from GUID to integer
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?
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?
You do not have the required permissions to view the files attached to this post.
-
- 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
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:
(Add JS in form's Custom Code)
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)