I cannot find an option to cascade update or delete in the model api. Am wondering if there is a manual out there that can help me pass this db option when sycning the db.
我找不到在模型api中级联更新或删除的选项。我想知道是否有一个手册可以帮助我在sycning db时传递这个db选项。
any idea's?
知道的吗?
1 个解决方案
#1
1
Look at the ForeignKey docs. It says:
看看国外的文件。它说:
When an object referenced by a ForeignKey is deleted, Django by default emulates the behavior of the SQL constraint ON DELETE CASCADE and also deletes the object containing the ForeignKey. This behavior can be overridden by specifying the on_delete argument.
当一个被外国密钥引用的对象被删除时,Django默认会在删除级联上模拟SQL约束的行为,并删除包含了ForeignKey的对象。可以通过指定on_delete参数来重写此行为。
So the default behavior is to cascade on delete, but you can change it by specifying something like this:
所以默认的行为是在删除时层叠,但是你可以通过指定如下的东西来改变它:
class Foobar(models.Model):
user = models.ForeignKey(User, on_delete=models.SET(User.objects.get_or_create(username="foooobarrrr")[0]))
#1
1
Look at the ForeignKey docs. It says:
看看国外的文件。它说:
When an object referenced by a ForeignKey is deleted, Django by default emulates the behavior of the SQL constraint ON DELETE CASCADE and also deletes the object containing the ForeignKey. This behavior can be overridden by specifying the on_delete argument.
当一个被外国密钥引用的对象被删除时,Django默认会在删除级联上模拟SQL约束的行为,并删除包含了ForeignKey的对象。可以通过指定on_delete参数来重写此行为。
So the default behavior is to cascade on delete, but you can change it by specifying something like this:
所以默认的行为是在删除时层叠,但是你可以通过指定如下的东西来改变它:
class Foobar(models.Model):
user = models.ForeignKey(User, on_delete=models.SET(User.objects.get_or_create(username="foooobarrrr")[0]))