Rails中的add_foreign_key与add_reference [英] add_foreign_key vs add_reference in rails
问题描述
rails中的"add_foreign_key" 和"add_reference" 方法有什么区别?
What is the difference between "add_foreign_key" and "add_reference" methods in rails?
据Rails官方指南,我所了解的是,它们都用于在两个表之间创建外键约束.
According to rails official guide all I understand is that they both are used to create foreign key constraint between two tables.
推荐答案
add_foreign_key
-添加新的外键. from_table
是带有键列的表,to_table
包含引用的主键.
add_foreign_key
- adds a new foreign key. from_table
is the table with the key column, to_table
contains the referenced primary key.
add_reference
-是同时创建列,索引和外键的快捷方式.
add_reference
- is meant as a shortcut for creating a column, index and foreign key at the same time.
什么是foreign key
-外键是表中的一个字段或一组字段,可以唯一地标识另一个表中的行.
What is foreign key
- a foreign key is a field or group of fields in a table that uniquely identifies a row in another table.
这篇关于Rails中的add_foreign_key与add_reference的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!