Skip to content
Advertisement

knex migration – ‘ER_INVALID_DEFAULT: Invalid default value for ‘timestamp’

I have a knex chema migration to create a table, with the line –

exports.up = async function(knex) {
return knex.schema.createTable("newTable", table => {
table.timestamp("timestamp").notNullable();
})
}

I am getting an error ER_INVALID_DEFAULT: Invalid default value for 'timestamp'

I’ve tried to give a default of null and remove the notNullable() or a default of CURRENT_TIMESTAMP but nothing seems to work (maybe I have a wrong syntax?)

I’d appreciate any help!

Advertisement

Answer

If you have access to my.ini (mysql conf file) remove the NO_ZERO_DATE from sql-mode and restart the server.

You can check it with SHOW VARIABLES LIKE ‘sql_mode’

For the complete answer, follow the link

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement