###やりたいこと
下記のようなマイグレーションファイルがあります。
三つのカラムを消去したのですが、後からacctivated
カラムだけ必要になったので
テーブルに戻したいと思っています。
手順としては
rails db:rollback
で全て戻す
→create_at
カラムとupdate_at
カラムをremoveするようにこのファイルを書き換える。
→rails db:migrate
を実行
このように考えています
ruby
1class DeleteToUsercolum < ActiveRecord::Migration[5.2] 2 def up 3 remove_column :users,:activated 4 remove_column :users,:create_at 5 remove_column :users,:update_at 6 end 7 8 def down 9 add_column :users, :activated , :boolean 10 add_column :users, :create_at, :datetime 11 add_column :users,:update_at, :datetime 12 13 end 14end 15
###エラーメッセージ
変更を取り消したいのでrails db:rollback
を実行しました
ts21:qusary ***$ rails db:rollback rails aborted! NameError: uninitialized constant ActiveSupport::EventedFileUpdateChecke /Users/****/Desktop/challecara/qusary/config/environments/development.rb:53:in `block in <main>' /Users/****/Desktop/challecara/qusary/config/environments/development.rb:1:in `<main>' /Users/****/Desktop/challecara/qusary/config/environment.rb:5:in `<main>' bin/rails:4:in `<main>' Caused by: NameError: uninitialized constant ActiveSupport::EventedFileUpdateChecke /Users/****/Desktop/challecara/qusary/config/environments/development.rb:53:in `block in <main>' /Users/****/Desktop/challecara/qusary/config/environments/development.rb:1:in `<main>' /Users/****/Desktop/challecara/qusary/config/environment.rb:5:in `<main>' bin/rails:4:in `<main>' Tasks: TOP => db:rollback => db:load_config => environment (See full trace by running task with --trace)
このエラーに関して調べたのですが参考文献が少なく、解決方法をご享受願いたいです。
また、前述の手順に不備や改善点があればぜひ教えていただきたいです。
エラーメッセージで指し示されている、/config/environments/development.rbの53行目は、どの様になっていますか?
```
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join('tmp', 'caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{2.days.to_i}"
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecke //53行目
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
host = '<aqueous-escarpment-97262>.herokuapp.com'
config.action_mailer.default_url_options = { host: host }
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
end
```
ファイルの全コードに//53行目を記しました。
このようになります
ご回答ありがとうございます。
編集して上記の手順でrollbackからmigration
という形でよろしいでしょうか?
回答2件
あなたの回答
tips
プレビュー