简体   繁体   中英

How to ignore pending migrations?

I have a Rails app that connects to another Rails app database. They have several common models. When using console, everything works fine (ActiveRecord queries tables properly), but when using a web server, Rails checks for pending migrations and raises error Migrations are pending . I want to pass this check as these 2 apps have different migrations. And just start the server. I tried:

config.active_record[:migration_error] = false
config.active_record.migration_error = false

but no luck. How can I make Rails ignore those pending migrations? Skip this check? Or is there a way to name them somehow, or set appropriate mtime , to last migration file?

Try this in the appropriate environment file in In RAILS_ROOT/config/environments/ like development.rb , staging.rb or production.rb

config.active_record.migration_error = false

Since rails stores migration information in a table called schema_migrations. So can add the version from your migration into that table to skip a specific migration. The version is the number string which comes before the description in the file name.

Alternatively, you can rename your migration for example from

20160801105511_your_table.rb

to

.20160801105511_your_table.rb

Add a dot at the start of the filename. Hope it will work.

Doesn't seem to work if you put it in the main application.rb

Seems to only work if you put it in a specific env config, for example development.rb:

# development.rb
config.active_record.migration_error = false

... and restart your server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM