首页 > 解决方案 > 列 ID 不存在 Heroku

问题描述

在此处输入图像描述 部署后我的 Heroku 页面出现错误

我尝试了很多东西并在谷歌上搜索了很多,但这些解决方案对我不起作用。有没有人可以给我一些关于我能做什么的提示。我真的迷路了。提前致谢

https://buildblock-site.herokuapp.com

联系人/models.py

class CompanyInformation(models.Model):
    id = models.AutoField(primary_key=True, unique=True)
    #
    #

设置.py

import django_on_heroku
DEBUG = True
ALLOWED_HOSTS = ['buildblock-site.herokuapp.com', '127.0.0.1']

#
#
#

django_on_heroku.settings(locals())
DEFAULT_AUTO_FIELD='django.db.models.AutoField'


'django.contrib.sessions.middleware.SessionMiddleware',

轮廓

web: gunicorn portfolio.wsgi

需求.py

asgiref==3.3.4
dj-database-url==0.5.0
Django==3.2
django-on-heroku==1.1.2
django-widget-tweaks==1.4.8
gunicorn==20.1.0
Pillow==8.2.0
psycopg2-binary==2.8.6
pytz==2021.1
sqlparse==0.4.1
whitenoise==5.2.0

我用了:

git add .  
git add -A
git commit -m ".."
git push heroku master   
heroku run python manage.py makemigrations   
heroku run python manage.py migrate contacts  
heroku ps:scale web=1    
heroku local web  

标签: djangopostgresqlheroku

解决方案


我所做的一切是为了让它为寻求解决方案的人们服务。所以这至少对我有用..

在根目录创建Procfile

web: gunicorn Portfolio.wsgi --log-file=-

heroku login
heroku keys:add #get SSL key

创建一个 Heroku 应用程序(我是在网站上完成的)创建一个 GitHub 存储库并将所有内容推送到上面,然后我转到 Heroku 部署页面,连接到我的 GitHub 并推送部署我的分支 btn

它给了我一些错误,所以我做到了

heroku config:set DISABLE_COLLECTSTATIC=1

还是错误???然后我将它添加到我的settings.py

from pathlib import Path
import os
import django_on_heroku
import dj_database_url
from decouple import config

ALLOWED_HOSTS = ['127.0.0.1', 'portfolio-buildblock.herokuapp.com']

INSTALLED_APPS = [
    #
    'whitenoise.runserver_nostatic',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

# Static files
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'portfolio/static')
]

# Media folder settings
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'


STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
django_on_heroku.settings(locals())

我的网址.py

urlpatterns = [
    #
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns += staticfiles_urlpatterns()

后来我看到没有静态文件???所以我做了这个

heroku config:unset DISABLE_COLLECTSTATIC 

在这之后

heroku config:set DISABLE_COLLECTSTATIC=1 
heroku config:set DJANGO_STATIC_HOST=https://d4663kmspf1sqa.cloudfront.net 

不要问我为什么……我不知道

最后我添加了数据库 Settings.py

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql_psycopg2",
        "NAME": "dynamo",
        "USER": "username",
        "PASSWORD": "pass",
        "HOST": "localhost",
        "PORT": "5432",
    }
}

它对我有用

如果这不起作用...删除 Heroku 应用程序并重试或检查拼写错误


推荐阅读