Core: Error when creating new migration and keep default value for the timestamp

Created on 30 Aug 2020  路  5Comments  路  Source: adonisjs/core

Package version

Framework version 5.0.0-preview-rc-1.11

Node.js and npm version

Node v12.16.1
Npm 6.13.7

Using node ace make:migration event

Sample Code (to reproduce the issue)

import BaseSchema from '@ioc:Adonis/Lucid/Schema'

export default class Events extends BaseSchema {
  protected tableName = 'event'

  public async up () {
    this.schema.createTable(this.tableName, (table) => {
      table.increments('id')
      table.timestamps(true)
    })
  }

  public async down () {
    this.schema.dropTable(this.tableName)
  }
}

The default value "table.timestamps(true)" do that error :
fatal Error: ER_INVALID_DEFAULT: Invalid default value for 'updated_at'

Removing true : table.timestamps() , solve the problem.

Thanks !

Question

Most helpful comment

Hey @Reptiluka! :wave:

If you are using MySQL, you need to use table.timestamps(true, true) to correctly set the default value of updated_at field.

All 5 comments

Against which database you are running the migration?

Hey @Reptiluka! :wave:

If you are using MySQL, you need to use table.timestamps(true, true) to correctly set the default value of updated_at field.

@thetutlage it's MySQL

@RomainLanz ok I will try that ! Maybe it was written in Knex.js doc, but in Adonisjs doc I don't find this, so it was confusing haha.

Thank you !

@Reptiluka So how did you resolved the problem?

Thanks!

Hi @ezehlivinus !
I followed the reply from @RomainLanz , so .timestamps(true, true) instead of .timestamps(true)

Was this page helpful?
0 / 5 - 0 ratings