django报错 django.db.utils.IntegrityError: null value in column “first_name“ violates not-null constra
django3.2使用openGauss数据库在创建superuser的时候报错django.db.utils.IntegrityError: null value in column "first_name" violates not-null constraint虽然官方文档写的是first_name 和 last_name字段是可选属性,django的createsuper命令也没有这两个属
·
django3.2使用openGauss数据库在创建superuser的时候报错django.db.utils.IntegrityError: null value in column "first_name" violates not-null constraint
虽然官方文档写的是first_name 和 last_name字段是可选属性,django的createsuper命令也没有这两个属性的选项。
解决方法:
在django项目下打开终端进入djangoshell模式手动插入user
python manage.py shell
导入User模型类
from django.contrib.auth.models import User
创建用户对象
user = User(username='test',email='test@qq.com')
为创建的user对象的属性赋值
user.first_name='test'
user.last_name='test'
user.is_superuser = True
user.is_active = True
user.is_staff = True
user.password = 'test123'
将user信息存入数据库
user.save()
此时在数据库中的auth_user表中就有了相对应的记录。
不过此时用户密码是明文存放在数据库中的,不符合django规范,还不能使用该用户登录admin管理后台
更改test用户密码:
python manage.py changepassword test
这样就可以用test用户登录admin管理后台了
更多推荐
已为社区贡献8条内容
所有评论(0)