Django 1到Django 2 on_delete错误

时间:2022-07-23 03:38:00

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.

我相信这个工作流程是为以前的Django版本创建的。现在,当我尝试升级它时,添加on_delete会出错。这是我所做的,但它仍然没有工作,我想知道我做错了什么。

ORIGINAL

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)

MY VERSION

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.

然后我得到另一个错误,说模型没有定义。

1 个解决方案

#1


0  

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

根据Django 2.0文档(以及发行说明),所有Foreignkey字段现在都有一个必需的on_delete参数。

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

你的模型领域似乎缺少它。发行说明还建议您查看迁移:

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.

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

#1


0  

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

根据Django 2.0文档(以及发行说明),所有Foreignkey字段现在都有一个必需的on_delete参数。

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

你的模型领域似乎缺少它。发行说明还建议您查看迁移:

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.

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