DEV Community

Alexandre Calaça
Alexandre Calaça

Posted on

How to temporarily skip the pending migration check in Rails

Introduction

In a typical Rails development workflow, database migrations play a critical role in evolving the schema as the application grows.

Rails, by default, checks for pending migrations when starting the server, and if any exist, it raises an ActiveRecord::PendingMigrationError.

While this safeguard prevents inconsistencies, there are times when temporarily skipping this check can be helpful.


Reproduce the error

Launch the server

rails server
Enter fullscreen mode Exit fullscreen mode

Open the page

localhost:3000
Enter fullscreen mode Exit fullscreen mode

Check the error

ActiveRecord::PendingMigrationError
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=development
You have 1 pending migration:
Enter fullscreen mode Exit fullscreen mode

Output

Image Check the error


Solution


Skip Migration pending

The first solution is to use the SKIP_PENDING_MIGRATIONS_CHECK=true command before you launch the server.

SKIP_PENDING_MIGRATIONS_CHECK=true rails server
Enter fullscreen mode Exit fullscreen mode

OUtput

Image Skip Migration pending


Uncomment Migration check

In the application.rb file or in any of the environments file, such as the config/environments/development.rb file.

Change this line

  config.active_record.migration_error = :page_load
Enter fullscreen mode Exit fullscreen mode

to

  config.active_record.migration_error = false
Enter fullscreen mode Exit fullscreen mode

OUtput

Image Uncomment Migration check

If you do not have the previous line, just add it.


Done


Top comments (0)