Petros Kyriakou
Petros Kyriakou

Reputation: 5343

Migration column not created on heroku db, visible on local - Rails

this is the migration file

class CreateComments < ActiveRecord::Migration
      def change
        create_table :comments do |t|
          t.string :name
          t.string :email
          t.text :body
          t.boolean :spam, default: false
          t.references :post, index: true, foreign_key: true
          t.references :user, index: true, foreign_key: true

          t.timestamps null: false
        end
      end
    end

the user_id column is not created on heroku for some reason.

actual table on heroku

Comment(id: integer, name: string, email: string, body: text, post_id: integer, created_at: datetime, updated_at: datetime)

I have tried heroku restart maybe it updates schema or something but nothing.

on my local env i can see and can work with user_id column.

Upvotes: 1

Views: 357

Answers (2)

Itay Grudev
Itay Grudev

Reputation: 7426

I suppose instead of creating a new migration you modified an existing one.

What you need to do is rollback the migration on Heroku and than migrate it again.

Keep in mind that you will have to create two commits to your repo, one withwout the modifications and on with. This is due to the fact that when rolling back the migration the added column should be missing or it will attempt to delete a column that does not exists.

So the procedure is the following:

  1. Remove the modifications from the migration. Commit the changes.
  2. heroku run rake db:rollback STEP=1 or however many steps you need.
  3. Add the modifications again. Commit the changes.
  4. heroku run rake db:migrate

Upvotes: 1

FabKremer
FabKremer

Reputation: 2169

Try the following - I'm supposing that is your last migration -

heroku run rake db:rollback to rollback the last migration

heroku run rake db:migrate to run that migration again

Upvotes: 0

Related Questions