diff --git a/lib/dialects/mysql/query/mysql-querycompiler.js b/lib/dialects/mysql/query/mysql-querycompiler.js index 52dd18b263..a235c64f04 100644 --- a/lib/dialects/mysql/query/mysql-querycompiler.js +++ b/lib/dialects/mysql/query/mysql-querycompiler.js @@ -131,7 +131,7 @@ class QueryCompiler_MySQL extends QueryCompiler { output(resp) { const out = resp.reduce(function (columns, val) { columns[val.COLUMN_NAME] = { - defaultValue: val.COLUMN_DEFAULT, + defaultValue: val.COLUMN_DEFAULT === 'NULL' ? null : val.COLUMN_DEFAULT, type: val.DATA_TYPE, maxLength: val.CHARACTER_MAXIMUM_LENGTH, nullable: val.IS_NULLABLE === 'YES', diff --git a/test/integration2/query/misc/additional.spec.js b/test/integration2/query/misc/additional.spec.js index 30c9237105..913ee7d84b 100644 --- a/test/integration2/query/misc/additional.spec.js +++ b/test/integration2/query/misc/additional.spec.js @@ -423,6 +423,27 @@ describe('Additional', function () { expect(expectedUuid).to.equal(originalUuid); }); + it ('#5154 - should properly mark COLUMN_DEFAULT as null', async function () { + if (!isMysql(knex)) { + return this.skip(); + } + + await knex.schema.dropTableIfExists('null_col'); + await knex.schema.createTable('null_col', function (table) { + table.date('foo').defaultTo(null).nullable(); + }) + const columnInfo = await knex('null_col').columnInfo(); + + expect(columnInfo).to.deep.equal({ + foo: { + type: 'date', + maxLength: null, + nullable: true, + defaultValue: null, + }, + }); + }); + it('#2184 - should properly escape table name for SQLite columnInfo', async function () { if (!isSQLite(knex)) { return this.skip();