Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Migration Error w/ Postgres when pushing to Heroku

Tags:

I'm trying to perform the following up migration to change the column "number" in the "tweet" model's table

class ChangeDataTypeForTweetsNumber < ActiveRecord::Migration   def up     change_column :tweets do |t|       t.change :number, :integer     end   end    def down     change_table :tweets do |t|       t.change :number, :string     end   end end 

Upon performing the the following up migration to heroku....

heroku rake db:migrate:up VERSION=20120925211232 

I get the following error

    PG::Error: ERROR:  column "number" cannot be cast to type integer : ALTER TABLE "tweets" ALTER COLUMN "number" TYPE integer 

Any thoughts you have would be very much appreciated.

Thanks everyone.

like image 820
dougiebuckets Avatar asked Sep 26 '12 14:09

dougiebuckets


People also ask

How do I migrate a specific migration in Rails?

To run a specific migration up or down, use db:migrate:up or db:migrate:down . The version number in the above commands is the numeric prefix in the migration's filename. For example, to migrate to the migration 20160515085959_add_name_to_users. rb , you would use 20160515085959 as the version number.

How Rails db Migrate works?

When you run db:migrate, rails will check a special table in the database which contains the timestamp of the last migration applied to the database. It will then apply all of the migrations with timestamps after that date and update the database table with the timestamp of the last migration.


1 Answers

Same as above but a little bit more concise:

change_column :yourtable, :column_to_change, 'integer USING CAST("column_to_change" AS integer)' 
like image 63
riley Avatar answered Sep 22 '22 20:09

riley