2017-08-27 8 views
0

参照キーをクラスからKlassに変更したいと考えています。どのようにこれを行うか分からない。私はそれが素早く列の名前を変更すると仮定していますが、私は決して外部キーを変更することに慣れていません。私はそれが簡単だと確信していますが、何かをねじにしたくありません。外部キーの名前を変更する

class Schedule < ActiveRecord::Migration[5.1] 
    def change 
    create_table :schedules, id: false do |t| 
     t.references :class, index: true, foreign_key: true 
     t.references :student, index: true, foreign_key: true 
     t.timestamps 
    end 
    end 
end 

答えて

0

solution in the APIがあります。

class Schedule < ActiveRecord::Migration[5.1] 
    def change 
    create_table :schedules, id: false do |t| 
     t.references :class, index: true, foreign_key: {name: 'by_klass'} 
     t.references :student, index: true, foreign_key: true 
     t.timestamps 
    end 
    end 
end 

あなたの答えをもう一度見て、私はそれがあなたが変更したい名前であるかどうかは分かりません。したがって、add_foreign_key documentationもご覧ください。私がnameを追加したのと同じ方法で、referencesコール内にリストされているオプションを使用することができます。私はそれがあなたが探しているcolumnオプションかもしれないと思う。

関連する問題