質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

2回答

3249閲覧

rails db:rollbackができない問題

ts21

総合スコア32

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2019/11/08 08:19

###やりたいこと
下記のようなマイグレーションファイルがあります。
三つのカラムを消去したのですが、後から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)

このエラーに関して調べたのですが参考文献が少なく、解決方法をご享受願いたいです。
また、前述の手順に不備や改善点があればぜひ教えていただきたいです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

maisumakun

2019/11/08 08:35

エラーメッセージで指し示されている、/config/environments/development.rbの53行目は、どの様になっていますか?
ts21

2019/11/08 16:57

``` 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 ```
ts21

2019/11/08 16:58

ファイルの全コードに//53行目を記しました。 このようになります
ts21

2019/11/09 00:34

ご回答ありがとうございます。 編集して上記の手順でrollbackからmigration という形でよろしいでしょうか?
guest

回答2

0

ベストアンサー

エラーメッセージのとおり、ActiveSupport::EventedFileUpdateCheckeというクラスは存在しません。正しくは、ActiveSupport::EventedFileUpdateCheckerと思われます。

投稿2019/11/08 22:12

maisumakun

総合スコア145184

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

エラーの原因はmaisumakunさんの質問に答えていただく所から始まります。
>前述の手順に不備や改善点があれば 
の方で。
2点あります。
rollbackして作りなおすのは薦めません。railsのmigration管理の方法を熟知するまでは。特に、本番リリースしてしまった後は。

大抵の場合、先へ先へと進めます。rollbackが行うmigrationを作ります。今回の場合はadd_column :users, :activated , :boolean なmigrationを作る。

2つめは、
モデルのtableからcreated_at, updated_atを削除するのはやめたほうが良いです。save、updateの時に updated_atがないというエラーが出るのではないかと懸念。

投稿2019/11/08 13:34

winterboum

総合スコア23347

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ts21

2019/11/08 17:00

的確なアドバイスをいただきありがとうございます。 以後気を付けたいと思います、
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問