I'm getting the below error message, not sure how to resolve it. Can anyone help please?
NoMethodError: undefined method `needs_migration?' for ActiveRecord::Migrator:Class
Here is the config.ru code:
require './config/environment'
if ActiveRecord::Migrator.needs_migration?
raise 'Migrations are pending. Run `rake db:migrate` to resolve the issue.'
end
use Rack::MethodOverride
use UsersController
use ArtworkController
run ApplicationController
change your code to
if ActiveRecord::Base.connection.migration_context.needs_migration?
raise 'Migrations are pending. Run `rake db:migrate` to resolve the issue.'
end
Fast forward to Rails 7.2, when they finally removed the long-deprecated method:
ActiveRecord::Base.connection.migration_context.needs_migration?
As of Rails 7.2 (or earlier?) the way to test for missing migration in code looks like:
ActiveRecord::Migration.check_all_pending!
That method doesn't return a boolean, but raises an error if migrations are pending. To boolify it you have to rescue. Something like this:
def migrations_missing?
ActiveRecord::Migration.check_all_pending!
false
rescue ActiveRecord::PendingMigrationError
true
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With