LoginSignup
0
0

More than 5 years have passed since last update.

migrationファイルで利用できる主なメソッドまとめ

Posted at

migration:名詞・移住
→Railsで、テーブルの作成・変更をするしくみ
migrationファイル(ex: 20160801xxxx_create_users.rb)ファイル先頭はタイムスタンプ値
→DBのスキーマ変更を記載

メソッド 概要
create_table テーブルの作成
change_table テーブル定義の変更
add_column 新規カラムを追加
add_index 新規インデックスを追加
remove_column 既存のカラムを削除
remove_index 既存のインデックスを削除
rename_column(table_name,old,new) 既存のカラム名をoldからnewに変更
rename_index(table_name,old,new) 既存のインデックス名をoldからnewへ変更
rename_table(table_name,new) 既存のテーブル名をtable_nameからnewへ変更
execute(sql) 任意のSQL命令を実行
0
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
0
0