![](/img/trans.png)
[英]What Does ActiveRecord::MultiparameterAssignmentErrors Mean?
[英]ActiveRecord, what does “index: true” mean?
我正在編寫一個涉及外鍵的遷移。 查看我同事的代碼,我看到他添加了這一行: t.reference :tablename, index: true
t.reference 部分是有道理的,但我不知道index: true
是什么意思。 誰能告訴我? 我一直無法在文檔中找到它。
注意:這不是以下內容的重復: Rails ActiveRecord::Migration index: true 和 add_index 之間有什么區別? 這只區分了兩者,但沒有解釋它們的作用。
index: true
將數據庫索引添加到引用的列。 例如,如果創建一個 :products 表:
create_table :products do |t|
t.references :user, index: true
end
這將在名為index_products_on_user_id
的products
表中的user_id
列上創建一個非唯一索引。
好吧,當你創建這個add_reference的東西時,你要告訴rails在“產品表”中添加user_id。 我認為id對連接不同的表很有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.