I had a column called “prize”:
create_table :contests do |t|
t.text :prize
I recently realized that this will always be an integer and I wanted to set a default value:
def change
change_column :contests, :prize, :integer, :default => 200
This works fine on my local machine, where I am using MySQL DB. However, when I push to my production site (which is hosted on Heroku, which gives me a Postgres DB) I get the following error:
PGError: ERROR: column "prize" cannot be cast to type "pg_catalog.int4"
: ALTER TABLE "contests" ALTER COLUMN "prize" TYPE integer
In this article: http://www.postgresonline.com/periodical.php?i_id=3 they discuss the use of the USING to solve this problem. But I don’t know how I can do that, and whether this is appropriate for what I’m trying to do.
Any insight into figuring this out would be very much appreciated.
Thanks!
Ringo
First you should use the same DB in both environments to prevent this kind of surprises.
To run raw sql in migrations see this example http://guides.rubyonrails.org/migrations.html#using-the-up-down-methods