Skip to content

Instantly share code, notes, and snippets.

@yazumoto
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save yazumoto/f42f76e7b9229e76ebc7 to your computer and use it in GitHub Desktop.

Select an option

Save yazumoto/f42f76e7b9229e76ebc7 to your computer and use it in GitHub Desktop.
RailsのMigrationのまとめ

Migrationまとめ

コマンドの方法

Index追加の例

rails g migration AddUniqueIndexToUser
class AddUniqueIndexToUser < ActiveRecord::Migration
  def change
    add_index :users, [:name], :unique => true
  end
end

列の追加、削除の例

class AddColumnToUser < ActiveRecord::Migration
  def change
    add_column :users, :nickname, :string, default: 'nick'
    remove_column :users, :age
  end
end
@yazumoto
Copy link
Author

参考になるURL
http://railsdoc.com/migration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment