lang
1class CreateBanks < ActiveRecord::Migration[5.0] 2 def change 3 create_table :banks, id: :string do |t| 4 t.string :name, null: false 5 t.string :kana, null: false 6 end 7 add_index :banks, :kana 8 end 9end 10 11class CreateBankBranches < ActiveRecord::Migration[5.0] 12 def change 13 create_table :bank_branches, id: :string do |t| 14 t.references :bank, foreign_key: true 15 t.string :name, null: false 16 t.string :kana, null: false 17 end 18 add_index :banks, :kana 19 end 20end
これをマイグレーションしようとするとbank_branchesを作成しようとしたときにbank_idをintegerで作成しようとしてしまい失敗します。
どのように書けばidがstringのテーブルを参照することができるのでしょうか?
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/10 09:36
2017/01/10 09:47
2017/01/10 10:06
2017/01/12 06:46