A story about an error when trying to add a date type column.
% rails db:migrate
== 20201220042102 DeviseCreateUsers: migrating ================================
-- create_table(:users)
rails aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Invalid default value for 'birthday'
/Users/bon/projects/furima-32411/db/migrate/20201220042102_devise_create_users.rb:5:in `change'
/Users/bon/projects/furima-32411/bin/rails:9:in `<top (required)>'
/Users/bon/projects/furima-32411/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Caused by:
ActiveRecord::StatementInvalid: Mysql2::Error: Invalid default value for 'birthday'
/Users/bon/projects/furima-32411/db/migrate/20201220042102_devise_create_users.rb:5:in `change'
/Users/bon/projects/furima-32411/bin/rails:9:in `<top (required)>'
/Users/bon/projects/furima-32411/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Caused by:
Mysql2::Error: Invalid default value for 'birthday'
/Users/bon/projects/furima-32411/db/migrate/20201220042102_devise_create_users.rb:5:in `change'
/Users/bon/projects/furima-32411/bin/rails:9:in `<top (required)>'
/Users/bon/projects/furima-32411/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
It seems like this happened before ... I specified the date type for birthday, but from the error statement, I felt that it was close to what I had done before. As a result of various investigations, the date type is still set to empty with the default value, It seems that the setting of "** default:" "**" is unnecessary. Delete the description from the migration file and migrate again, success.
t.date :birthday, null: false #← Here "default": ""Because there was an error
Dynamic and static values, confusing.
Recommended Posts