Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL 8.0.13 CURRENT_DATE as default knex throws ER_INVALID_DEFAULT at migrate:down #3958

Open
nogurenn opened this issue Aug 1, 2020 · 0 comments

Comments

@nogurenn
Copy link

nogurenn commented Aug 1, 2020

Environment

Knex version: 0.21.2
Database + version: MySQL 8.0.19
OS: Mac OS 10.14.6

Bug

  1. Expected behaviour

down() would work as expected after running in the CLI. MySQL supports CURRENT_DATE as default value for DATE columns as of 8.0.13. See https://dev.mysql.com/doc/refman/8.0/en/data-type-defaults.html#data-types-defaults-explicit

  1. Error message
Error: ER_INVALID_DEFAULT: Invalid default value for 'search_date'
    at Function.get (/Users/glenn/Developer/apollo/yelp-core/node_modules/knex/lib/util/make-knex.js:42:26)
    at Object.exports.down (/Users/glenn/Developer/apollo/yelp-core/db/knex_migrations/20200801195748_create_search_terms.js:37:15)
    at /Users/glenn/Developer/apollo/yelp-core/node_modules/knex/lib/migrate/Migrator.js:543:36
    at /Users/glenn/Developer/apollo/yelp-core/node_modules/knex/lib/transaction.js:184:22
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
  1. Reduced test code
exports.up = function(knex) {
  return knex.schema.createTable('my_table', function(t) {
    t.increments().primary();

    // this is now valid as of MySQL 8.0.13, but migrate:down complains saying invalid default
    // migrate:up works perfectly fine. Inserting into table yields proper default date
    t.date('search_date').defaultTo(knex.raw('(CURRENT_DATE)')); 
  });
};

exports.down = function(knex) {
  return knex.schema.dropTable(name);  // the error gets thrown here
};
@nogurenn nogurenn changed the title MySQL 8.0.13 CURRENT_DATE as default throws ER_INVALID_DEFAULT at migrate:down MySQL 8.0.13 CURRENT_DATE as default knex throws ER_INVALID_DEFAULT at migrate:down Aug 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant