An error occurs when trying to migrate by writing the necessary information in the migration file. I think it's strange, but first try resetting.
% rails db:migrate:reset
↓ ↓ ↓ Results below ↓ ↓ ↓
Dropped database 'protospace_32411_development'
Dropped database 'protospace_32411_test'
Created database 'protospace_32411_development'
Created database 'protospace_32411_test'
== 20201214092753 DeviseCreateUsers: migrating ================================
-- create_table(:users)
rails aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: BLOB/TEXT column 'profile' can't have a default value
#The following is omitted
Something is wrong··· But I don't know what it is. Let's try again.
% rails db:migrate
↓ ↓ ↓ Results below ↓ ↓ ↓
== 20201214092753 DeviseCreateUsers: migrating ================================
-- create_table(:users)
rails aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: BLOB/TEXT column 'profile' can't have a default value
#The following is omitted
Is it no good? If you look closely at the output result of the terminal here, you will finally notice the same error statement.
Mysql2::Error: BLOB/TEXT〜〜
After investigating what it means, if you want to add a column with a NULL constraint to the table, the default value is fine. However, it seems that MySQL cannot give a default value to BLOB/TEXT type. When you check the migration file
users.rb
t.string :name, null: false, default: ""
t.text :profile, null: false, default: nil #← Here is """”, So changed
Resolved by changing the default value to "** nil **". When the engineer became stronger beyond the error, I felt like I read it somewhere, but I realized that feeling for the first time. It's refreshing to be able to solve it alone! I'll do my best tomorrow, too.
Recommended Posts