使用django写博客项目时遇到的问题
1. 继承django中的AbstractUser类,然后在生成迁移文件时,报错。
原因是在继承的AbstractUser类中写了一个一对一字段。
解决办法:不用了user原生类了,自己写密码加密验证,就这么尿性。
2. 解决完上一个问题,在生成迁移文件时,报错。
ERRORS: policies.Site.user: (fields.E300) Field defines a relation with model 'User', which is either not installed, or is abstract. policies.Site.user: (fields.E307) The field policies.Site.user was declared with a lazy reference to 'policies.user', but app 'policies' doesn't provide model 'user'. policies.Site_user.user: (fields.E307) The field policies.Site_user.user was declared with a lazy reference to 'policies.user', but app 'policies' doesn't provide model 'user'.
原因:跨app建表时,有外键,或者一对一,一对多字段。
解决办法:在字段关联表前加入了app名称,例如:app.表名
blog = models.OneToOneField('blog.Blog', null=True, on_delete=models.CASCADE)
3. 解决问题1.
1. 首先settings.py中配置
AUTH_USER_MODEL = '继承user类的表'
2. 原因,其实是问题2造成,问题2解决了,就没问题了