Tim Mitchell
Tim Mitchell

Reputation: 653

Removing a bad column from a table

I have a ruby-on-rails web application in which I incorrectly added a column to a table.

What I did was in my migration file I put:

add_column :my_table, :string, :col_name

When of course I should have put:

add_column :my_table, :col_name, :string

Basically, I switched the column name and type.

It actually did add the column - but without any type. If I examine the table in the console, it displays a column with the name 'string' but does not list any type.

Now, I can't remove it. If I do

remove_column: my_table, :string

I get a nil exception.

Any suggestions?

Thanks in advance, Tim

Upvotes: 0

Views: 83

Answers (3)

zeantsoi
zeantsoi

Reputation: 26193

Find the version number and run the down migration:

rake db:migrate:down VERSION=unique_stamp

Also, ensure that you're passing arguments to the function as symbols, not strings:

remove_column :my_table, :string

Upvotes: 2

yellowskull
yellowskull

Reputation: 177

You could try renaming the :string column?

rename_column :my_table, :string, :col_name

Upvotes: -1

Ian Kenney
Ian Kenney

Reputation: 6426

you could try rolling back the migration

rake db:rollback

see : http://guides.rubyonrails.org/migrations.html

Upvotes: 0

Related Questions