本文介绍了Rails中的add_foreign_key与add_reference的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 08:40