2

When trying to deploy my Rails app to Railway I'm getting the following error:

ActiveRecord::PendingMigrationError

Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=development
You have 1 pending migration:
20221102234102_create_contacts.rb

I'm able to get the app online by clicking a button that appears below the message, which says "Run Pending Migration". I would like to Find a method to auto run that migration every deploy.

I've tried everything listed in Getting: "Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue." after cloning and migrating the project

So I've run:

      rm -f db/*.sqlite3
      rake db:create
      RAILS_ENV=development bundle exec rake db:migrate
      rails s -e development

to no success.

The contents of the "20221102234102_create_contacts.rb" file are as follows:

class CreateContacts < ActiveRecord::Migration[7.0]
  def change
    create_table :contacts do |t|
      t.string :name
      t.string :email
      t.text :comments
      t.timestamps
    end
  end
end

I'm completely new to web development and was following a free bootcamps videos to get this far, but they are using Heroku and that was unsuccessful, and since Heroku will no longer be free I figured I should try Railway out instead.

1 Answers1

0

Railway will use a Procfile to start your service, so an easy way to make sure your migrations are run is to use this.

In the root folder of your app, add a file called Procfile (no extension)

Here's a sample from one of my apps:

web: /bin/bash -l -c "rake db:migrate && bundle exec puma -C config/puma.rb"

This first runs rake db:migrate then it starts a puma server using the configurations I've defined in config/puma.rb

This command runs once after a successful build.

Chiperific
  • 4,428
  • 3
  • 21
  • 41