django創(chuàng)建超級(jí)用戶時(shí)指定添加其它字段方式
使用 python manage.py createsuperuser創(chuàng)建超級(jí)用戶時(shí)只能默認(rèn)輸入:用戶名,郵箱,及密碼來(lái)創(chuàng)建
有的時(shí)候我們需要?jiǎng)?chuàng)建的時(shí)候指定額外的字段,可以通過(guò)下面的方法
使用 python manage.py shell 進(jìn)入shell腳本
在shell腳本中
from users.models import UserUser.objects.create_superuser(’用戶名’,’郵箱’,’密碼’,mobile=19111111111)# User.objects.create_superuser()# 前三個(gè)字段是固定的,可以通過(guò)關(guān)鍵字參數(shù)來(lái)指定需要添加的額外參數(shù)
補(bǔ)充知識(shí):dajngo創(chuàng)建超級(jí)用戶 createsuper 報(bào)錯(cuò)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;', },
然后刪除數(shù)據(jù)庫(kù) 重新運(yùn)行一遍
python manage.py createsuperuser
以上這篇django創(chuàng)建超級(jí)用戶時(shí)指定添加其它字段方式就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 詳解Android studio 動(dòng)態(tài)fragment的用法2. 什么是python的自省3. 解決Android studio xml界面無(wú)法預(yù)覽問(wèn)題4. Spring Boot和Thymeleaf整合結(jié)合JPA實(shí)現(xiàn)分頁(yè)效果(實(shí)例代碼)5. 圖文詳解vue中proto文件的函數(shù)調(diào)用6. php模擬實(shí)現(xiàn)斗地主發(fā)牌7. Springboot Druid 自定義加密數(shù)據(jù)庫(kù)密碼的幾種方案8. Vue封裝一個(gè)TodoList的案例與瀏覽器本地緩存的應(yīng)用實(shí)現(xiàn)9. vue 使用localstorage實(shí)現(xiàn)面包屑的操作10. Vuex localStorage的具體使用

網(wǎng)公網(wǎng)安備