Elliot
Elliot

Reputation: 13835

Rails 3, migration works locally, does not work in Heroku?

I recently posted this question

which worked locally with the answer I selected as correct, here is the migration I used essentially:

class ChangeColumnToUsers < ActiveRecord::Migration
  def self.up
    change_column :users, :created_at, :datetime

  end

  def self.down
    change_column :users, :created_at, :string
  end
end

After running heroku rake db:migrate, I received this error:

rake aborted!
An error has occurred, this and all later migrations canceled:

PGError: ERROR:  column "deadline" cannot be cast to type "date"
: ALTER TABLE "tasks" ALTER COLUMN "deadline" TYPE date

(See full trace by running task with --trace)
(in /disk1/home/slugs/18c5c920-2e22-40f5-8d6a-b20a0fc5d7ba/mnt)
==  ChangeColumnToUsers: migrating ============================================
-- change_column(:users, :created_at, :datetime)

Any ideas?

Upvotes: 3

Views: 923

Answers (2)

Pasta
Pasta

Reputation: 1790

I would migrate back, delete the field, create the new field.

I did this plenty of times, worked like a charm.

Upvotes: 0

Elliot
Elliot

Reputation: 13835

Here is the work around I found on SO!

How do I change column type in Heroku?

Upvotes: 3

Related Questions