Django 1到Django 2 on_delete错误 [英] Django 1 to Django 2 on_delete error

查看:55
本文介绍了Django 1到Django 2 on_delete错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信此工作流程是为先前的Django版本创建的。现在,当我尝试升级它时,添加on_delete时出现错误。这是我所做的,但仍无法正常工作,我想知道自己在做错什么。

I believe this workflow was created for a previous Django version. Now when I am trying to upgrade it I get an error to add on_delete. Here is what I have done but it is still not working and I'm wondering what I am doing wrong.

原始

class Task(AbstractEntity):
    request = ForeignKey(Request, related_name='tasks')   
    assignee = ForeignKey(Group)    
    updated_by = ForeignKey(User)    
    activity_ref = CharField(max_length=100)    
    status = CharField(verbose_name="Status", max_length=30, choices=TASK_STATUS)

我的版本

class Task(models.AbstractEntity):
    request = models.ForeignKey(Request, related_name='tasks', on_delete=models.CASCADE)
    assignee = ForeignKey(Group)
    updated_by = ForeignKey(User)
    activity_ref = CharField(max_length=100)
    status = CharField(verbose_name="Status", max_length=30, choices=TASK_STATUS)

然后我收到另一个错误,指出未定义模型。

Then I get another error saying the model is not defined.

推荐答案

根据 Django 2.0文档(以及发行说明)全部外键字段现在具有必需的 on_delete 参数。

According to the Django 2.0 docs (and also the release notes) all Foreignkey fields now have a required on_delete parameter.

它似乎在模型的字段中缺失。发行说明还建议您查看迁移情况:

It seems to be missing on your model's fields. The release notes also advise to take a look at your migrations:


模型和迁移中现在需要ForeignKey和OneToOneField的on_delete参数。考虑压缩迁移,以便减少更新的数量。

The on_delete argument for ForeignKey and OneToOneField is now required in models and migrations. Consider squashing migrations so that you have fewer of them to update.

这篇关于Django 1到Django 2 on_delete错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆