UUID-Field is not automatically generating UUIDs when more than one field is being created along the UUID-Field?

Before I report this as a bug.
The following situation came up, when I tried to create a new table (mariadb on docker; server = nodejs) with an increments field and an uuid field.
Always, when I create the uuid field on itself, it is being created in knex as follows:


exports.up = function(knex) {
  return knex.schema
    .raw(knex.client.constructor.name.startsWith('Client_PG') ? 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp"' : 'SELECT 1')
    .createTable('test5', async function (table) {
      table.uuid('testuuid').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
    .dropTable('test5')
};

As far as I understand the knex code, the uuid will always automatically generate, if other fields will be populated.

Now, when I try to create a table with an increments field and an uuid field, the following happens:


exports.up = function(knex) {
  return knex.schema
    .createTable('test6', async function (table) {
      table.increments('id');
      table.uuid('uuid');
    })

};

exports.down = function(knex) {
  return knex.schema
    .dropTable('test6')
};

There is no automatic generation anymore? At least when it comes to the fundamental creation of the table, as there are no options being set for the uuid table.
Is this a feature or a bug?
(I know there is still another possibility of creating uuids in server connect, still this bugged me somehow, if it was intentionally handled this way).

There is already a bug report for this. Seems to be a few uuid related issues at present.

1 Like