簡體   English   中英

在 Django 中創建超級用戶時出錯

[英]Error creating superuser in Django

我正在嘗試創建一個超級用戶來訪問我的應用程序中的 Django 管理框架。 我在 Windows 8.1 機器上使用 Vagrant:

> ./manage.py createsuperuser

但是,我收到以下錯誤:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, i
n execute_from_command_line
    utility.execute()
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, i
n execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in ru
n_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in ex
ecute
    output = self.handle(*args, **options)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsu
peruser.py", line 141, in handle
    self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
  File "/vagrant/myapp/accounts/managers.py", line 52, in create_superuser
    return self._create_user(email, password, True, True, **extra_fields)
  File "/vagrant/myapp/accounts/managers.py", line 31, in _create_user
    user.set_slug()
  File "/vagrant/myapp/accounts/models.py", line 164, in set_slug
    slug = slugify(self.username, max_length=50).lower()
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/slugify/main.py", line 101, in slugify
    text = join_words(words, separator, max_length)
  File "/home/vagrant/Envs/myapp/local/lib/python2.7/site-packages/slugify/main.py", line 78, in join_words
    text = next(words)    # text = words.pop(0)
StopIteration

我在其他地方( 這里)和( 這里)讀到這是一個“語言環境”問題,但我的理解是這是一個 OSX 錯誤,我在一個流浪的虛擬機上......?

使用--username標志而不是直接傳遞用戶名:

python manage.py createsuperuser --username thisismyusername

我遇到了同樣的問題,在遷移更改后,我能夠創建超級用戶。

試試這個:

python manage.py makemigrations

python manage.py migrate

python manage.py createsuperuser

只是因為您在創建模型后尚未應用遷移。 所以運行

python manage.py makemigrations然后python manage.py migrate

現在遷移已應用,您可以通過運行創建超級用戶

python manage.py createsuperuser

我使用 SQL Lite 刪除了 DB 文件並運行以下命令:

python manage.py migrate
python manage.py makemigrations

我使用每一個提示,但我遇到問題 C:\Users\Komal\Desktop\instaclones\instaclones>python manage.py runserver 使用 StatReloader 監視文件更改 執行系統檢查...

系統檢查未發現任何問題(0 靜音)。 2022 年 7 月 23 日 - 07:46:31 Django 版本 4.0.5,使用設置 'instaclones.settings' 在http://127.0.0.1:8000/啟動開發服務器 使用 CTRL-BREAK 退出服務器。

C:\Users\Komal\Desktop\instaclones\instaclones>python manage.py makemigrations 未檢測到更改

C:\Users\Komal\Desktop\instaclones\instaclones>python manage.py migrate 要執行的操作:應用所有遷移:管理員、身份驗證、內容類型、會話、用戶 運行遷移:沒有要應用的遷移。

C:\Users\Komal\Desktop\instaclones\instaclones>python manage.py createsuperuser 用戶名:komal 密碼:密碼(再次):錯誤:您的密碼不匹配。 密碼:不遷移應用請幫助我

$ run python manage.py syncdb

系統會嘗試同步並詢問:

You have installed Django's auth system, and don't have any superusers                  defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'yogesh'): 
Email address: yogesh.gupta38@gmail.com
Password: 
Password (again): 
Superuser created successfully.

我遇到了同樣的問題,這些東西在我的情況下有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM