前提・実現したいこと
React
とDjango
でブログを作りデプロイするところです。
git push heroku master
をしたのですが、エラーが出ます。
データベースを指定できていないようです。
指定の仕方がわからないため苦戦しています。
発生している問題・エラーメッセージ
django.db.utils.OperationalError: could not connect to server: No such file or directory
psycopg2.OperationalError: could not connect to server: No such file or directory
log全文
1➜ ElectronicJournal git:(master) git push heroku master 2Counting objects: 4, done. 3Delta compression using up to 8 threads. 4Compressing objects: 100% (4/4), done. 5Writing objects: 100% (4/4), 384 bytes | 384.00 KiB/s, done. 6Total 4 (delta 3), reused 0 (delta 0) 7 8文字数制限のためカット 9 10 11remote: 12remote: Traceback (most recent call last): 13remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection 14remote: self.connect() 15remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect 16remote: self.connection = self.get_new_connection(conn_params) 17remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection 18remote: connection = Database.connect(**conn_params) 19remote: File "/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py", line 126, in connect 20remote: conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 21remote: psycopg2.OperationalError: could not connect to server: No such file or directory 22remote: Is the server running locally and accepting 23remote: connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? 24remote: 25remote: 26remote: The above exception was the direct cause of the following exception: 27remote: 28remote: Traceback (most recent call last): 29remote: File "manage.py", line 22, in <module> 30remote: execute_from_command_line(sys.argv) 31remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line 32remote: utility.execute() 33remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute 34remote: self.fetch_command(subcommand).run_from_argv(self.argv) 35remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv 36remote: self.execute(*args, **cmd_options) 37remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute 38remote: output = self.handle(*args, **options) 39remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped 40remote: res = handle_func(*args, **kwargs) 41remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 87, in handle 42remote: executor = MigrationExecutor(connection, self.migration_progress_callback) 43remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__ 44remote: self.loader = MigrationLoader(self.connection) 45remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__ 46remote: self.build_graph() 47remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/loader.py", line 212, in build_graph 48remote: self.applied_migrations = recorder.applied_migrations() 49remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 73, in applied_migrations 50remote: if self.has_table(): 51remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 56, in has_table 52remote: return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()) 53remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 256, in cursor 54remote: return self._cursor() 55remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 233, in _cursor 56remote: self.ensure_connection() 57remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection 58remote: self.connect() 59remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__ 60remote: raise dj_exc_value.with_traceback(traceback) from exc_value 61remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection 62remote: self.connect() 63remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect 64remote: self.connection = self.get_new_connection(conn_params) 65remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection 66remote: connection = Database.connect(**conn_params) 67remote: File "/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py", line 126, in connect 68remote: conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 69remote: django.db.utils.OperationalError: could not connect to server: No such file or directory 70remote: Is the server running locally and accepting 71remote: connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? 72remote: 73remote: Waiting for release... failed. 74To https://git.heroku.com/electronic-journal-asuha.git 75 0dfa57a..4e16b5c master -> master
該当のソースコード
プロジェクトツリー
C:. │ .gitignore │ docker-compose.yml │ manage.py │ package.json │ Procfile │ requirements.txt │ runtime.txt │ yarn.lock │ ├─backend │ Dockerfile │ requirements.txt │ ├─blog │ │ admin.py │ │ apps.py │ │ forms.py │ │ models.py │ │ permissions.py │ │ serializers.py │ │ tests.py │ │ urls.py │ │ views.py │ │ __init__.py │ │ │ ├─migrations │ │ │ 0001_initial.py │ │ │ 0002_comment.py │ │ │ 0003_auto_20190711_0907.py │ │ │ __init__.py │ │ │ │ │ └─__pycache__ │ │ 0001_initial.cpython-37.pyc │ │ 0002_comment.cpython-37.pyc │ │ 0003_auto_20190711_0907.cpython-37.pyc │ │ __init__.cpython-37.pyc │ │ │ ├─static │ │ └─css │ │ blog.css │ │ │ ├─templates │ │ └─blog │ │ base.html │ │ post_detail.html │ │ post_edit.html │ │ post_list.html │ │ │ └─__pycache__ | 文字数制限のためカット │ ├─frontend │ Dockerfile │ README.md │ ├─mysite │ │ settings.py │ │ urls.py │ │ wsgi.py │ │ __init__.py │ │ │ └─__pycache__ │ settings.cpython-37.pyc │ urls.cpython-37.pyc │ wsgi.cpython-37.pyc │ __init__.cpython-37.pyc │ ├─public │ favicon.ico │ index.html │ manifest.json │ └─src │ App.js │ App.test.js │ index.js │ routes.js │ serviceWorker.js │ ├─components │ Article.js │ Comment.js │ CommentForm.js │ Form.js │ Loading.js │ requirements.txt │ ├─containers │ ArticleDetailView.js │ ArticleListView.js │ Layout.js │ Login.js │ Signup.js │ └─store │ utility.js │ ├─actions │ actionTypes.js │ auth.js │ └─reducers auth.js
setting.py
py
1 2import os 3 4# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 5BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 6 7文字数制限のためカット 8 9ALLOWED_HOSTS = ['electronic-journal-asuha.herokuapp.com'] 10 11 12文字数制限のためカット 13 14 15# Database 16# https://docs.djangoproject.com/en/1.11/ref/settings/#databases 17 18DATABASES = { 19 'default': { 20 'ENGINE': 'django.db.backends.postgresql', 21 'NAME': os.path.join(BASE_DIR, '/var/run/postgresql/.s.PGSQL.5432'), 22 } 23} 24 25 26 27 28 29文字数制限のためカット 30 31 32# Static files (CSS, JavaScript, Images) 33# https://docs.djangoproject.com/en/1.11/howto/static-files/ 34 35STATIC_URL = '/static/' 36STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') 37STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' 38 39CORS_ORIGIN_ALLOW_ALL = True 40 41ACCOUNT_EMAIL_VERIFICATION = 'none' 42ACCOUNT_AUTHENTICATION_METHOD = 'username' 43ACCOUNT_EMAIL_REQUIRED = False 44
wsgi.py
py
1import os 2 3from django.core.wsgi import get_wsgi_application 4from whitenoise.django import DjangoWhiteNoise 5 6os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") 7 8application = DjangoWhiteNoise(application)
Procfile
release: python manage.py migrate web: gunicorn mysite.wsgi --log-file -
runtime.txt
python-3.6.6
requirements.txt
Django>=2.0,<3.0 psycopg2>=2.7,<3.0 djangorestframework djangorestframework-jwt django-rest-auth>=0.9.3 django-allauth>=0.37.1 django-cors-headers gunicorn==19.7.1 django-heroku whitenoise==3.3.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。