Skip to content

Mysql2::Error occured when execute migration datetime column with default option in Rails 7.0 #43292

@hotatekaoru

Description

@hotatekaoru

Steps to reproduce

git clone git@github.com:hotatekaoru/rails_7_sample.git
cd rails_7_sample
bundle install
bin/rails db:create
bin/rails db:schema:load

Then the following error occurs.

rails aborted!
ActiveRecord::StatementInvalid: Mysql2::Error: Invalid default value for 'registered_at'
path_to_project/sample/db/schema.rb:15:in `block in <main>'
path_to_project/sample/db/schema.rb:13:in `<main>'

Caused by:
Mysql2::Error: Invalid default value for 'registered_at'
path_to_project/sample/db/schema.rb:15:in `block in <main>'
path_to_project/sample/db/schema.rb:13:in `<main>'
Tasks: TOP => db:schema:load
(See full trace by running task with --trace)

In Rails 7.0, Error occurs if you are using MySQL and there is a migration file with datetime columns with default option created in Rails 6.1 or earlier.

Also, if you execute migrate add_column or create_table with datetime columns with default option, an error will occur.

After the following PR merged, an error has occurred.
#42297

Expected behavior

not failure migration.

Actual behavior

Mysql2 error occurs.

System configuration

Rails version:
v7.0.0 alpha2
Ruby version:
v3.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions