我是Django的初学者,如果我缺少一些必要的信息,请原谅我。我最近在settings.py上修改了我的数据库,运行时不断出现错误
git push heroku master
错误块如下:
Counting objects: 22, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (22/22), done.
Writing objects: 100% (22/22), 4.84 KiB | 825.00 KiB/s, done.
Total 22 (delta 12), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: ! Python has released a security update! Please consider upgrading to python-3.6.8
remote: Learn More: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> Installing requirements with pip
remote:
remote: -----> $ python manage.py collectstatic --noinput
remote: Traceback (most recent call last):
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 20, in <module>
remote: import psycopg2 as Database
remote: ModuleNotFoundError: No module named 'psycopg2'
remote: During handling of the above exception, another exception occurred:
remote: Traceback (most recent call last):
remote: File "manage.py", line 15, in <module>
remote: execute_from_command_line(sys.argv )
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
remote: utility.execute()
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
remote: django.setup()
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
remote: apps.populate(settings.INSTALLED_APPS)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate
remote: app_config.import_models()
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models
remote: self.models_module = import_module(models_module_name)
remote: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
remote: return _bootstrap._gcd_import(name[level:], package, level)
remote: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
remote: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
remote: File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
remote: File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
remote: File "<frozen importlib._bootstrap_external>", line 678, in exec_module
remote: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
remote: from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
remote: class AbstractBaseUser(models.Model):
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 101, in __new__
remote: new_class.add_to_class('_meta', Options(meta, app_label))
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 305, in add_to_class
remote: value.contribute_to_class(cls, name)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/options.py", line 203, in contribute_to_class
remote: self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/__init__.py", line 33, in __getattr__
remote: return getattr(connections[DEFAULT_DB_ALIAS], item)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 202, in __getitem__
remote: backend = load_backend(db['ENGINE'])
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 110, in load_backend
remote: return import_module('%s.base' % backend_name)
remote: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
remote: return _bootstrap._gcd_import(name[level:], package, level)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/ base.py", line 24, in <module>
remote: raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
remote: django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
remote:
remote: ! Error while running '$ python manage.py collectstatic --noinput'.
remote: See traceback above for details.
remote:
remote: You may need to update application code to resolve this error.
remote: Or, you can disable collectstatic for this application:
remote:
remote: $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote: https://devcenter.heroku.com/articles/django-assets
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to ewbunlv.
remote:
To https://git.heroku.com/ewbunlv.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/ewbunlv.git'
这是我settings.py更改的一部分(最初是Django具有的默认数据库)
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', #Used 'django.db.backends.postgresql' as well
'NAME': 'myname',
USER': 'user',
'PASSWORD': 'password',
'HOST': 'host',
'PORT': '5432',
}
}
我的要求。txt:
awscli==1.16.91
boto==2.49.0
boto3==1.9.81
botocore==1.12.81
certifi==2018.11.29
chardet==3.0.4
colorama==0.3.9
dj-database-url==0.5.0
Django==2.1.4
django-cleanup==3.0.1
django-s3-folder-storage==0.5
django-storages==1.7.1
docutils==0.14
gunicorn==19.9.0
heroku==0.1.4
idna==2.8
jmespath==0.9.3
Pillow==5.3.0
pyasn1==0.4.5
python-dateutil==2.7.5
pytz==2018.7
PyYAML==3.13
requests==2.21.0
rsa==3.4.2
s3transfer==0.1.13
six==1.12.0
urllib3==1.24.1
whitenoise==4.1.2
我已经奔跑
heroku run python manage.py collectstatic --dry-run --noinput
,它运行正常,没有任何错误。我已经为此工作了一段时间,但无济于事。
它在本地也能正常工作,但是当我尝试将其转换为生产版本时,出现上述错误。我想念什么?
答案 0 :(得分:1)
heroku config:set DISABLE_COLLECTSTATIC=1
git push heroku master (or git push heroku <branch>:master if not on master)
heroku run python manage.py migrate
heroku run 'bower install --config.interactive=false;grunt prep;python manage.py collectstatic --noinput'
heroku config:unset DISABLE_COLLECTSTATIC
heroku run python manage.py collectstatic
答案 1 :(得分:0)
就像Chris,Phd和Selcuk提到的那样,似乎我忽略了我requirements.txt文件中的一些必要部分。我用过
pip freeze
,然后再次将其复制/粘贴到requirements.txt文件中,这一次就可以使用了。