首页 文章

Django auth定制

提问于
浏览
0

我想自定义django auth应用程序,因为默认的auth应用程序无法完成我们项目所需的一切 . 然后我通过在这里查看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

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

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

  • 0

    确保您遵循了文档的this part .

    粗略地说,它表示您需要更改在FK中引用用户的方式 .

    The Right way to do it when you use customized user: (文档示例)

    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个位置进行此更改 .

相关问题