Ecto.Migrations.references / 2中的on_delete选项做什么? [英] What do the on_delete options in Ecto.Migrations.references/2 do?
本文介绍了Ecto.Migrations.references / 2中的on_delete选项做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Ecto文档描述了<$ c可用的选项$ c> references / 2 ,但没有记录这些选项的作用。可用的选项有:
The Ecto documentation describes the options available to references/2
, but does not document what those options do. The options available are:
-
:没有
-
:delete_all
-
:nilify_all
-
:限制
:nothing
:delete_all
:nilify_all
:restrict
它们是做什么的?
推荐答案
这实际上是一个SQL问题。
This is actually a SQL question at root.
The PostgreSQL文档清楚地概述了这些选项:
The PostgreSQL documentation outlines these options clearly:
-
:没什么
-如果在检查约束时仍然存在任何引用行,则会引发错误;如果您未指定任何内容,则这是默认行为。 -
:delete_all
-指定在删除引用的行时,row( s)引用它的同时也应自动删除 -
:nilify_all
-导致引用行中的引用列),则在删除引用行时将其设置为nil
-
:restrict
-防止删除引用的行。如果存在被引用的对象,它将失败。
:nothing
- if any referencing rows still exist when the constraint is checked, an error is raised; this is the default behavior if you do not specify anything.:delete_all
- specifies that when a referenced row is deleted, row(s) referencing it should be automatically deleted as well:nilify_all
- causes the referencing column(s) in the referencing row(s) to be set tonil
when the referenced row is deleted:restrict
- prevents deletion of a referenced row. It will fail if there is a referenced object.
:没有和
:restrict
相似,但:
这两个选择之间的本质区别是
[:nothing
]允许将支票推迟到
事务中的稍后,而[:restrict
]不会。
the essential difference between these two choices is that [
:nothing
] allows the check to be deferred until later in the transaction, whereas [:restrict
] does not.
这篇关于Ecto.Migrations.references / 2中的on_delete选项做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文