[Ruby] Setting values ​​and memorandum for the table

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

[Ruby] Setting values ​​and memorandum for the table
Default values for MaxHeapSize and InitialHeapSize
Write keys and values in Ruby
[Ruby] Boolean values ​​and logical operators
[Ruby] Obtaining even values ​​using the even? Method
Memorandum (Ruby: Basic Grammar: Classes and Instances)
Ruby setting 2
It feels good to prepare different classes for the same table values
A memorandum to clean up the code Ruby
[Ruby] Arguments with keywords and default values of arguments
Compare the speed of the for statement and the extended for statement.
[Ruby] Regular expression for secure password policy setting
Ruby setting 3 Rubocop
[Ruby] Method memorandum
Ruby and Gem
[Ruby] I thought about the difference between each_with_index and each.with_index
Feel the basic type and reference type easily with ruby
[For beginners] DI ~ The basics of DI and DI in Spring ~
[Grails] About the setting area and the setting items of application.yml
Tips for setting the initial delay for Poller in XML
Rewrite the code for java.io.File with java.nio.Path and java.nio.Files
Memorandum (Ruby: Basic grammar: Use by naming the process)
Setting up the CentOS 8KVM hypervisor and CentOS virtual machine
Feel the basic type and reference type easily with ruby 2
[Technical memo] About the advantages and disadvantages of Ruby
[Ruby] Class nesting, inheritance, and the basics of self
A memorandum about table data types and commands (Rails)