我的问题来自我想模仿SQL中的“更新级联”的情况(当我更新ID并且有一个外国键时,它将自动更新),但我意识到(显然)没有(显然)存在一种本地方法。
我已经访问他试图做同样的事情。
我的问题是:为什么Django没有本地选项?那是不良的习俗吗?如果是这样,为什么?这会给我的软件或结构带来问题吗?
有什么简单的方法吗?
提前致谢!
My question comes from a situation where I want to emulate the ON UPDATE CASCADE in SQL (when I update an id and I have a Foreignkey, it is going to be automatically updated) in Django, but I realized that (apparently) doesn't exist a native way to do it.
I have visited this old question where he is trying to do the same.
My question is: Why Django doesn't have a native option? Is that a bad practice? If so, why? Does that bring problems to my software or structure?
Is there a simple way to do this?
Thanks in advance!
发布评论
评论(1)
考虑更新关键字段是一种不好的做法。请注意,该字段用于索引生成和其他计算昂贵的操作。这就是为什么关键字段必须包含标识记录的唯一且无法重复的值的原因。它不一定必须具有寄存器内容的直接含义,而是自动值。如果您需要更新它,则可能需要将值放在表的另一个字段中才能完成,而不会影响关系。
正是由于这个原因,您在Django中找不到您想要的操作。
It is a bad practice to think about updating key fields. Note that this field is used for index generation and other computationally expensive operations. This is why the key fields must contain a unique and unrepeatable value that identifies the record. It does not necessarily have to have a direct meaning with the content of the register, it can be an autonumeric value. If you need to update it, you may need to put the value in another field of the table to be able to do it without affecting the relationships.
It is for this reason that you will not find in Django the operation you are looking for.