1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Rails migration

Posted at

命名規則

terminal.sh
rails generate migration CreateProducts name:string 
rails generate migration AddPartNumberToProducts
rails generate migration RemovePartNumberFromProducts 
rails generate migration AddUserRefToProducts user:references
rails generate migration CreateJoinTableCustomerProduct

changeを使う

Active Recordがマイグレーションを逆進させる(以前のマイグレーションに戻す)方法を自動的に理解してくれるため、多くの場面で利用できます。up/downを書かなくて良い。

  • add_column
  • add_foreign_key
  • add_index
  • add_reference
  • add_timestamps
  • change_column_default(:fromと:toの指定は省略不可)
  • change_column_null
  • create_join_table
  • create_table
  • disable_extension
  • drop_join_table
  • drop_table(ブロックが必須)
  • enable_extension
  • remove_column(型の指定が必須)
  • remove_foreign_key(第2テーブルの指定が必須)
  • remove_index
  • remove_reference
  • remove_timestamps
  • rename_column
  • rename_index
  • rename_table
参照

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?