thiebo
thiebo

Reputation: 1435

after postgres import from heroku, rails locally imposes to run database migration

I'm trying to import my database from heroku back to local. Following the commands on heroku, I can import the entire database locally.

However, Rails is answering I have a pending migration and that I should run bin/rails db:migrate RAILS_ENV=development. That fails because the tables already exist.

On heroku:

heroku pg:info --app my_app
 ›   Warning: heroku update available from 7.22.7 to 7.24.4.
=== DATABASE_URL
Plan:                  Hobby-dev
Status:                Available
Connections:           0/20
PG Version:            11.2

Localy:

psql (PostgreSQL) 11.3

ActiveRecord::Migrator.current_version returns => 20190608070435 and db/schema.rb contains:

ActiveRecord::Schema.define(version: 2019_06_10_061746)

Replacing that version with the one given by ActiveRecord::Migrator.current_version also doesn't help.

Don't know where this problem comes from. After import from Heroku, I have the correct database locally, but rails sees a pending migration.

Upvotes: 0

Views: 46

Answers (1)

sameera207
sameera207

Reputation: 16629

Rails uses schema_migrations table to keep a track of migrations. This issue can happen when a corresponding migration record is missing and rails tries to run the migration. But it fails since you already have the table in your local DB.

If you are sure that you have the latest / up to date database locally, one thing you can do is to run the migration, but commenting out the code (that is in the migration). NOTE: make sure you only comment on the table creation code

E.g

class <your migraton name> < ActiveRecord::Migration[4.2]
  def change
    # commented out code
  end
end

That way Rails will update the schema_migrations table the correct version and will not nag you again (Rails assumes you've created the table).

Then uncomment the migration file.

Upvotes: 1

Related Questions