网络编程
位置:首页>> 网络编程>> Python编程>> django创建超级用户时指定添加其它字段方式

django创建超级用户时指定添加其它字段方式

作者:fanlei5458  发布时间:2022-08-13 17:24:18 

标签:django,创建,超级用户,字段

使用 python manage.py createsuperuser创建超级用户时只能默认输入:用户名,邮箱,及密码来创建

有的时候我们需要创建的时候指定额外的字段,可以通过下面的方法

使用 python manage.py shell 进入shell脚本

在shell脚本中


from users.models import User
User.objects.create_superuser('用户名','邮箱','密码',mobile=19111111111)

# User.objects.create_superuser()
# 前三个字段是固定的,可以通过关键字参数来指定需要添加的额外参数

补充知识:dajngo创建超级用户 createsuper 报错auth_user' doesn't exist

修改


DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'car',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '127.0.0.1',
'PORT': '3306',
'OPTIONS': {
 "init_command": "SET foreign_key_checks = 0;",
},
}
}

添加


'OPTIONS': {
 "init_command": "SET foreign_key_checks = 0;",
},

然后删除数据库 重新运行一遍

python manage.py createsuperuser

来源:https://blog.csdn.net/fanlei5458/article/details/80877755

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com