歡迎您光臨本站 註冊首頁

django創建超級用戶時指定添加其它字段方式

←手機掃碼閱讀     火星人 @ 2020-06-05 , reply:0

使用 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


[火星人 ] django創建超級用戶時指定添加其它字段方式已經有194次圍觀

http://coctec.com/docs/python/shhow-post-237017.html