Django auth定制

时间:2014-05-31 13:20:48

标签: django

我想自定义django auth app,因为默认的auth app无法完成我们项目所需的一切。然后我通过在这里查看django文档来自行解决。 https://docs.djangoproject.com/en/1.6/topics/auth/customizing/#a-full-example。我试着准确地做那个例子。最后,我在settings.py中添加了AUTH_USER_MODEL =“intelic_auth.MyUser”设置。但是当我尝试运行“python manage.py syncdb”时,我在下面遇到了这个错误。我不知道为什么。如果有人能帮助我搞清楚,我将非常感激。

CommandError: One or more models did not validate:

helpdesk.ticket: 'assigned_to' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.

helpdesk.followup: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.

helpdesk.savedsearch: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.

helpdesk.usersettings: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.

helpdesk.ticketcc: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.

2 个答案:

答案 0 :(得分:0)

确保您遵循了文档的this part

粗略地说,它说你需要改变你在FK中引用用户的方式。

使用自定义用户时执行此操作的正确方法:(文档示例)

class Article(models.Model):
    author = models.ForeignKey(settings.AUTH_USER_MODEL)

另外,如果您阅读了错误,看起来很清楚:Update the relation to point at settings.AUTH_USER_MODEL。由于您有5次此错误,您需要在models.py文件中的5个位置进行此更改。

答案 1 :(得分:0)

我几天前解决了这个问题。我试图通过添加更多字段的自定义模型对USer模型进行子类化。

我没有从User继承,而是改为AbstractUser,一切正常