前提・実現したいこと
MySQLのエラーを解消する方法です。長々と書いてしまいますが、ぜひお力を貸していただければと思います。
発生している問題・エラーメッセージ
AWSのEC2を使いデプロイを試みていますが、MySQLのエラーでつまづいています。データベースはRDSを使っています。
エラー内容は下記の通りで、「Intorductionというカラムはデフォルト値を持てないという」内容です。
データ型がtextだと、default値を持てないという認識です。
intorductionのデータ型をtext、defaultを""にしていたところエラーが出たため、
データ型をstringに変更しました。schema.rbも下記のように変更されています。
create_table "users", force: :cascade do |t| t.string "name", null: false t.string "introduction" t.string "profile_image_id" t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "email" t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
[ec2-user@ip-172-31-46-48 bookers2]$ bundle exec rails db:migrate RAILS_ENV=production == 20201023062453 DeviseCreateUsers: migrating ================================ -- create_table(:users) rails aborted! StandardError: An error has occurred, all later migrations canceled: Mysql2::Error: BLOB, TEXT, GEOMETRY or JSON column 'introduction' can't have a default value: CREATE TABLE `users` (`id` bigint NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` varchar(255) DEFAULT '' NOT NULL, `introduction` text DEFAULT '' NOT NULL, `profile_image_id` varchar(255), `encrypted_password` varchar(255) DEFAULT '' NOT NULL, `reset_password_token` varchar(255), `reset_password_sent_at` datetime, `remember_created_at` datetime, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `_query' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `block in query' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `handle_interrupt' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `query' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:187:in `block (2 levels) in execute' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:186:in `block in execute' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract_adapter.rb:581:in `block (2 levels) in log' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract_adapter.rb:580:in `block in log' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/notifications/instrumenter.rb:23:in `instrument' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract_adapter.rb:571:in `log' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:185:in `execute' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/mysql/database_statements.rb:28:in `execute' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:311:in `create_table' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:871:in `block in method_missing' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:840:in `block in say_with_time' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:840:in `say_with_time' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:860:in `method_missing' /home/ec2-user/bookers2/db/migrate/20201023062453_devise_create_users.rb:5:in `change' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:814:in `exec_migration' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:798:in `block (2 levels) in migrate' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:797:in `block in migrate' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `with_connection' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:796:in `migrate' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:977:in `migrate' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:1292:in `block in execute_migration_in_transaction' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:1345:in `ddl_transaction' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:1291:in `execute_migration_in_transaction' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:1263:in `block in migrate_without_lock' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:1262:in `each' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:1262:in `migrate_without_lock' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:1210:in `block in migrate' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:1363:in `with_advisory_lock' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:1210:in `migrate' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:1036:in `up' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:1011:in `migrate' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:172:in `migrate' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.4/lib/active_record/railties/databases.rake:60:in `block (2 levels) in <main>' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/commands/rake/rake_command.rb:23:in `block in perform' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/commands/rake/rake_command.rb:20:in `perform' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/command.rb:48:in `invoke' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/commands.rb:18:in `<main>' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:291:in `block in require' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:257:in `load_dependency' /home/ec2-user/bookers2/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:291:in `require' bin/rails:9:in `<main>'
試したこと
bundle exec rails db:migrate RAILS_ENV=productionを試みましたが、上記エラーが出てしまいます。
自分の考え
データ型を変えたのにエラーが出るということは、schema.rbの情報を読み込めていない??
補足情報(FW/ツールのバージョンなど)
Rails:Rails 5.2.4.4
Ruby:ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
MySQL:5.7.22
EC2
RDS