Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
811 views
in Technique[技术] by (71.8m points)

ruby - Rails 4 how to ignore pending migrations

Problem is following:

  • I have db/seed.rb full of initial data.
  • One of migrations depends on data this seed provides.
  • I'm trying to deploy my app from empty db.

Result is:

  • RAILS_ENV=production rake db:migrate - fails due to lack of initial data
  • RAILS_ENV=production rake db:seed - fails due to pending migrations

I wanted to somehow tell rake to ignore pending migrations, but unable to do it so far.

UPDATE (due to additional experience)

Sometimes migrations and model code goes out of sync, so migrations not being run. To avoid this problem recently used redefining of model in migrations:

# reset all callbacks, hooks, etc for this model
class MyAwesomeModel < ActiveRecord::Base
end

class DoSomethingCool < ActiveRecord::Migration
  def change
    ...
  end
end
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I am not very sure if this will help you. But I was looking for something and found this question. So it looks like this might help:

In RAILS_ROOT/config/environments/development.rb Set the following setting to false:

 config.active_record.migration_error = false#:page_load

In my situation it now does not show the pending migration error anymore. Should work for rake tasks and console for the same environment as well.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...