Help us understand the problem. What is going on with this article?

foreignerメモ

More than 5 years have passed since last update.

使い方がわからなかったのでメモ

add_foreign_key(from_table, to_table, options)

  • options = ハッシュ
key 説明
:name キー名
:column 対象カラム
:depend when :nullify then "ON DELETE SET NULL" when :delete then "ON DELETE CASCADE" when :restrict then "ON DELETE RESTRICT"
:options 自由入力っぽい

例)

def change
  add_foreing_key :table1, :table2, name: :table1_to_table2_fk
end

remove_foreign_key(table, options)

  • options = ハッシュのとき
key 外部キー名
:name 外部キー名(こっちが優先)
:column "#{table}#{column}fk"
  • options = ハッシュ以外 外部キーがtableとoptionsからきまる。
"#{table}_#{table.to_s.singularize}_id_fk"

例)

def change
  remove_foreing_key :table, name: :table1_to_table2_fk
end
3yatsu
スタープラチナが好きです。
http://miyatsu.hatenablog.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした