Database migrations, add nullable property

Edit: Jump to post #6 Database migrations, add nullable property

Hello,

I’m requesting the ability to add the “nullable” property when creating/changing table columns in the database manager.

For NodeJS projects, this can be achieved by appending .nullable() to the Knex builder, e.g.:

exports.up = function(knex) {
  return knex.schema
    .createTable('users', function (table) {
      table.increments('id');
      table.string('name').nullable();
      table.string('email');
      table.string('password');
    })
};

I haven’t tested how Wappler currently deals with null values, but since it doesn’t offer nullable columns so far I’m assuming it literally writes the string “NULL” instead of an actual NULL value, is this the case? If so, the behaviour would need to be changed to write NULL instead of “NULL” for columns containing a nullable property. As Wappler writes a db.json file containing column properties, it’s possible to check if the column is nullable without the overhead of checking directly with the database server itself.

I didn’t realize the Advanced view had a nullable property checkbox, thanks for that!

However, it looks like this feature request turns into a bug report instead.

Bug: When creating a new column, the .nullable() method is not applied, but if I edit an existing column, then the .nullable() method is applied (as far as my limited testing goes).

Question for Wappler team: How does Wappler handles columns with the .nullable() method applied? Does it still use the literal string “NULL”?

1 Like

I removed the comment because I saw it adds the notNullable() function and you asked explicitly for the nullable().

Did you double check?

Looks like there’s some bizarre behaviour here. The knex.up has notNullable(), but knex.down has nullable()

I haven’t posted here the migration because I don’t remember the exact steps I did. I might re-create the migrations and edit this post

Edit: Yeah, I probably messed up the migration and unticked the “NULL” checkbox, hence notNullable() was applied to knex.up. However, it does appends .nullable() for the migration reversal.

So the issue is .nullable() is not applied on column creation and change.

1 Like

Forget it @JonL, MariaDB actually shows the columns are nullable despite not being explicit in the migration files. Everything’s good!

Wappler team could still consider adding an explicit .nullable() in migration files to prevent confusion, if they wish :slight_smile:

1 Like