Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1 add columns with change_table migration

I have one table called profiles with some columns.

Now I wish to add a few columns to this table using the change-method in rails 3.1. I created a migration with the following code:

def change
  change_table :profiles do |t|
    t.string :photo
    t.string :name
    t.references :user
  end
end

The migration works perfectly, but when I want to rollback I get

SQLite3::SQLException: duplicate column name: photo: ALTER TABLE "profiles" ADD "photo" varchar(255)

Any ideas why?

like image 304
martnu Avatar asked Jul 20 '11 09:07

martnu


1 Answers

The auto-generated migrations for adding columns in Rails 3.1 is in the format:

class AddColumnToTable < ActiveRecord::Migration
  def change
    add_column :table, :column, :type
  end
end

Perhaps try that syntax?

like image 192
sevenseacat Avatar answered Oct 06 '22 01:10

sevenseacat