用户 table 不是在 django 部署上创建的,而是在 heroku bash 上创建的超级用户

user table not created on django deployment but superuser created on heroku bash

我正在尝试上传我的第一个 Django 应用程序,我已经为这个问题苦苦挣扎了一段时间,感谢您的帮助。

我已经在 heroku 上设置了我的项目,我遵循了这个教程:https://www.youtube.com/watch?v=6DI_7Zja8Zc in which django_heroku module is used to configure DB, here is the link to library https://pypi.org/project/django-heroku/

该应用程序在登录时抛出错误,就好像用户表不存在一样,但我已经使用 heroku bash 功能创建了一个超级用户,在使用“heroku 运行 python manage.py 迁移”。当我在 heroku bash 上 运行 "ls" 命令时,这是我的目录:

manage.py Procfile requirements.txt runtime.txt smoke staticfile

“smoke”是我的文件夹应用程序,我应该可以在这个目录中看到数据库吗?如果未创建数据库,我如何使用 heroku bash 功能创建超级用户?

这是 django 在服务器上给我的数据库配置:

{'default': {'ATOMIC_REQUESTS': False,
             'AUTOCOMMIT': True,
             'CONN_MAX_AGE': 0,
             'ENGINE': 'django.db.backends.sqlite3',
             'HOST': '',
             'NAME': PosixPath('/app/db.sqlite3'),
             'OPTIONS': {},
             'PASSWORD': '********************',
             'PORT': '',
             'TEST': {'CHARSET': None,
                      'COLLATION': None,
                      'MIGRATE': True,
                      'MIRROR': None,
                      'NAME': None},
             'TIME_ZONE': None,
             'USER': ''}}  

我看到 db 是 sqlite3,应该是 postgreSQL,但我知道 django-heroku 库应该这样做。

我不知道还有哪些其他信息可能有用,因为我没有部署任何东西的经验,所以我将等待更多信息请求来编辑这个问题。

我的 gitignore 文件是这样的:

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
#   For a library or package, you might want to ignore these files since the code is
#   intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
#   However, in case of collaboration, if having platform-specific dependencies or dependencies
#   having no cross-platform support, pipenv may install dependencies that don't work, or not
#   install all needed dependencies.
#Pipfile.lock

# poetry
#   Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
#   This is especially recommended for binary packages to ensure reproducibility, and is more
#   commonly ignored for libraries.
#   https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

这是我的 settings.py 文件的底部:

...

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfile')

STATIC_URL = '/static/'

django_heroku.settings(locals())

谢谢。

如果你看看 the django-heroku repository on GitHub 我想你会发现它已经被废弃了。它有一个标语

This repository has been archived by the owner. It is now read-only.

并且自 2018 年 10 月以来在 master 分支上没有新的提交。

The heroku-on-django library 旨在成为 django-heroku:

的更新替代品

This has been forked from django-heroku because it was abandoned and then renamed to django-on-heroku because old project has been archived.

它也有些停滞不前(在撰写本文时对 master 的最新提交是从 2020 年 10 月开始的)但它应该比 django-heroku.

更好用

无论哪种情况,请务必按照文档中的说明将其放在 settings.py 的底部:

# Configure Django App for Heroku.
import django_on_heroku
django_on_heroku.settings(locals())