Error when creating field type UUID (not as primary key)

Wappler Version : 6.7.1
Operating System : win 11
Server Model: node
Database Type: MySQL (cloud vioa docker)
Hosting Type: local

Expected behavior

Field type uuid should be created

Actual behavior

Knex error displayed

How to reproduce

I have a simple table

image

i add a field of type UUID WHICH IS NOT TO BE USED AS PRIMARY KEY, checkbox is not checked

image

and apply changes

Update fails

image

Looks like it is trying to make the field a primary key even though "Primary" checkbox is not checked.

Clue is in

Knex code

exports.up = function(knex) {
  return knex.schema
    .raw(knex.client.constructor.name.startsWith('Client_PG') ? 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp"' : 'SELECT 1')
    .table('testtable', async function (table) {
      table.uuid('myuuidfield').primary().defaultTo(knex.client.constructor.name.startsWith('Client_PG') ? knex.raw('uuid_generate_v4()')
              : (knex.client.constructor.name.includes('MSSQL') ? knex.raw('NEWID()')
                : (knex.client.constructor.name.includes('MySQL') ? knex.raw('(UUID())') : null)));
    })

};

exports.down = function(knex) {
  return knex.schema
    .table('testtable', async function (table) {
      table.dropColumn('myuuidfield');
    })
};
``

More strangly

On table refreshing schema it appears the field is actually created and at that stage is also shown as primary key

image

if i make a change to the field i.e. rename it

image

and apply changes

The error appears corrected

image

I have run into this bug as well.

If you open a terminal as root in the DB container, you can use the mysql tool to 'describe' the table for you.

root@yourserver# mysql -u root -p <database name>
mysql> show tables;
mysql> describe testtable;

Get the root password from Wappler's Project Options -> Targets
The result will show you if that column is defined as a primary key or not

I always forget my db name so you can also do

root@yourserver# mysql -u root -p
mysql> show databases;
mysql> use <database name>;

Then 'show tables;' if you need the name, or just 'describe

;'

1 Like