Home  >  Q&A  >  body text

knex migration - 'ER_INVALID_DEFAULT: Invalid default value for 'timestamp'

<p>I have a knex chema migration to create a table where one of the rows is -</p> <pre class="brush:php;toolbar:false;">exports.up = async function(knex) { return knex.schema.createTable("newTable", table => { table.timestamp("timestamp").notNullable(); }) }</pre> <p>I encountered an error<code>ER_INVALID_DEFAULT: Invalid default value for 'timestamp'</code></p> <p>I've tried giving a default value of null and removing notNullable(), or giving a default value of CURRENT_TIMESTAMP, but neither seems to work (maybe there's something wrong with my syntax?)</p> <p>I would appreciate any help! </p>
P粉269847997P粉269847997419 days ago376

reply all(1)I'll reply

  • P粉191323236

    P粉1913232362023-08-29 12:12:24

    If you can access my.ini (mysql configuration file), please remove NO_ZERO_DATE from sql-mode and restart the server.

    You can use SHOW VARIABLES LIKE 'sql_mode' command to check.

    For the complete answer, please click on the link

    reply
    0
  • Cancelreply