django 3.2-在 sqlite3 中创建超级用户时出错

Posted

技术标签:

【中文标题】django 3.2-在 sqlite3 中创建超级用户时出错【英文标题】:django 3.2- error creating superuser in sqllite3 【发布时间】:2021-11-19 04:33:44 【问题描述】:
PS C:\Users\Abdulla Zia\PycharmProjects\EnhanceImage> python manage.py createsuperuser
Username (leave blank to use 'abdullazia'): admin
Email address: 
Password: 
Password (again):
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\Abdulla Zia\AppData\Local\Programs\Python\Python37\Lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line      
    utility.execute()
  File "C:\Users\Abdulla Zia\AppData\Local\Programs\Python\Python37\Lib\site-packages\django\core\management\__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Abdulla Zia\AppData\Local\Programs\Python\Python37\Lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Abdulla Zia\AppData\Local\Programs\Python\Python37\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 79, in execute 
    return super().execute(*args, **options)
  File "C:\Users\Abdulla Zia\AppData\Local\Programs\Python\Python37\Lib\site-packages\django\core\management\base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "C:\Users\Abdulla Zia\AppData\Local\Programs\Python\Python37\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 157, in handle 
    validate_password(password2, self.UserModel(**fake_user_data))
  File "C:\Users\Abdulla Zia\AppData\Local\Programs\Python\Python37\Lib\site-packages\django\contrib\auth\password_validation.py", line 44, in validate_password       
    password_validators = get_default_password_validators()
  File "C:\Users\Abdulla Zia\AppData\Local\Programs\Python\Python37\Lib\site-packages\django\contrib\auth\password_validation.py", line 19, in get_default_password_validators
    return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS)
  File "C:\Users\Abdulla Zia\AppData\Local\Programs\Python\Python37\Lib\site-packages\django\contrib\auth\password_validation.py", line 30, in get_password_validators 
    validators.append(klass(**validator.get('OPTIONS', )))
  File "C:\Users\Abdulla Zia\AppData\Local\Programs\Python\Python37\Lib\site-packages\django\contrib\auth\password_validation.py", line 174, in __init__
    with gzip.open(password_list_path, 'rt', encoding='utf-8') as f:
  File "C:\Users\Abdulla Zia\AppData\Local\Programs\Python\Python37\lib\gzip.py", line 57, in open
    raise TypeError("filename must be a str or bytes object, or a file")
TypeError: filename must be a str or bytes object, or a file

执行了所有迁移仍然出现此错误。我删除了数据库文件并创建了新文件,但仍然出现相同的错误。服务器已启动并正在运行,没有任何错误

【问题讨论】:

显示您的AUTH_PASSWORD_VALIDATORS 设置(在settings.py 中) AUTH_PASSWORD_VALIDATORS = [ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', , 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', , 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', , 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', , ] 【参考方案1】:

请进行迁移并尝试创建超级用户 试试这个

python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser

或在您初次迁移时尝试此操作

python manage.py migrate
python manage.py createsuperuser

【讨论】:

您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center。 我已经尝试过这些命令。我没有工作!同样的问题。我什至删除了 sqldb3 文件并再次按照提到的顺序运行这些命令,仍然出现错误

以上是关于django 3.2-在 sqlite3 中创建超级用户时出错的主要内容,如果未能解决你的问题,请参考以下文章

Qt:如何在 qpushbutton 中创建超链接?

在python中创建超链接

在Textview中创建超链接[重复]

如何在 kivy 中创建超链接?

通过绑定在TextBlock中创建超链接

如何从 DJango 的 SQLite3 中删除表?