所以我試圖在表users
和looking_for_options
之間創建連接表。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]
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