I
I
Igor Lobazov2016-11-03 18:25:47
PostgreSQL
Igor Lobazov, 2016-11-03 18:25:47

How to migrate to Heroku?

class CreateMessages < ActiveRecord::Migration[5.0]
  def change
    create_table :messages do |t|
      t.string :message
t.references :room, foreign_key: true
      t.references :user, foreign_key: true

      t.timestamps
    end
  end
end

when executing heroku run rake db:migrate, the error PG::UndefinedTable: ERROR: relation "rooms" does not exist
I tried to comment out the line t.references :room, foreign_key: true
all migrations passed.
Tell me why t.references :room, foreign_key: true may not work

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Andreev, 2016-11-03
@igorrize

Set the column manually, something like this:
t.integer :room_id, index:true

R
Roman Mirilaczvili, 2016-11-03
@2ord

Make sure the rooms creation migration happens before this one.
After that, due to the fact that the database was migrated with a commented line, you need to roll back:
heroku run rake db:rollback

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question