したがって、テーブルusers
とlooking_for_options
の間にジョインテーブルを作成しようとしています。Rails create join tableのインデックス名が長すぎます
これは私のマイグレーションファイルです:
class CreateJoinTableOptionsUsers < ActiveRecord::Migration[5.0]
def change
create_join_table :looking_for_options, :users do |t|
t.index [:looking_for_option_id, :user_id]
t.index [:user_id, :looking_for_option_id]
end
end
end
しかし、私はこのエラーを取得しています:
Index name 'index_looking_for_options_users_on_looking_for_option_id_and_user_id' on table 'looking_for_options_users' is too long; the lim it is 64 characters
はjoin table
ため、rails
大会はTable_A_Name_Table_B_Name
であり、その列は、同様の規則に従うことを知っTable_A_id
およびTable_B_id
。
joint table
に短い列名を指定するにはどうすればrails
多対多の関連付けを中断しないのですか?
更新:
私は私だけではなく、インデックスに別の名前を付けることができることがわかりました。しかし、rails
の多対多関連が実際にそれを利用するでしょうか?
class CreateJoinTableOptionsUsers < ActiveRecord::Migration[5.0]
def change
create_join_table :looking_for_options, :users do |t|
t.index [:looking_for_option_id, :user_id], name: 'option_user'
t.index [:user_id, :looking_for_option_id], name: 'user_option'
end
end
end