我需要在遷移中創建外鍵讓has_many belongs_to工作嗎? 我可以不創建任何外鍵,例如:options =>「CONSTRAINT fk_box_storage REFERENCES box(id)」並仍然在模型中使用has_many和belong_to?遷移中的外鍵需要讓has_many belongs_to工作嗎?
0
A
回答
1
沒有必要,如果你只是想有一個Web應用程序訪問數據庫。如果你想用另一個應用程序或直接訪問數據庫,我會建議你創建外鍵,因爲它們會讓你更好地瞭解那裏正在發生的事情,不會讓你插入錯誤的信息或錯誤地刪除(如果你設置刪除選項)
3
相關問題
- 1. has_many realation是否需要外鍵?
- 2. has_many&belongs_to在postgres中使用外鍵和數據庫約束進行遷移?
- 3. LocomotiveCMS has_many/belongs_to不工作
- 4. Rails has_many/belongs_to不工作
- 5. 境界:需要遷移嗎?
- 6. 你需要belongs_to嗎?
- 7. Rails belongs_to has_many與自定義外鍵
- 8. Kohana ORM關係$ has_many和$ belongs_to和外鍵
- 9. Has_one,Belongs_to遷移
- 10. Doctrine遷移外鍵
- 11. 的has_many或belongs_to的工作錯
- 12. 外鍵使遷移
- 13. Coredata遷移真的需要嗎?
- 14. f.collection_select不工作rails 3(has_many/belongs_to)
- 15. Kohana - has_many和belongs_to不能正常工作
- 16. Elixir Ecto:如何使用belongs_to和has_many編寫遷移?
- 17. 爲什麼rails遷移包含belongs_to,但不包含has_many?
- 18. PHP工匠遷移外鍵錯誤
- 19. 的has_many/belongs_to的
- 20. 如何讓foreign_key在這個簡單的has_many,belongs_to關係中工作?
- 21. 試圖讓ef核心遷移工作遷移到.net core 2
- 22. 是否需要在has_many/belongs_to關係中生成ID?
- 23. Laravel 5.2遷移外鍵
- 24. ror - 包含has_many和belongs_to兩端的外鍵?
- 25. 活動記錄沒有設置與has_many和belongs_to的外鍵
- 26. Rails 3 ActiveAdmin。如何用不同的外鍵設置has_many和belongs_to?
- 27. Rails has_many和belongs_to與外鍵錯誤的關係
- 28. Rails has_one和belongs_to遷移?
- 29. 在Codeigniter遷移中添加外鍵
- 30. knex遷移創建外鍵
你是指a.destroy刪除?或者:dependent =>:destroy? – wizztjh 2010-11-19 18:25:17
在Rails中,刪除只會刪除單條記錄,銷燬將刪除記錄和子女。但是,另外當你通過控制檯或GUI進入你的數據庫時,如果由於某種原因你試圖刪除一條記錄,它不會讓你如果這會導致離開任何寄養兒童。 – 2010-11-19 19:29:18