DEV Community

Alexandre Calaça
Alexandre Calaça

Posted on

2

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


Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (2)

Collapse
 
jbranchaud profile image
Josh Branchaud

Does SKIP_PENDING_MIGRATIONS_CHECK=true rails server only work in specific Rails versions? I just tried that on a Rails 8 app and it had no effect. The config change, on the other. hand, did work.

Collapse
 
alexandrecalaca profile image
Alexandre Calaça

Thanks for the comment.

You might be right, I haven't test it in Rails 7 or 8.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more