Reputation: 143
It's the first time for me to deploy my wagtail app(and I'm very proud of that :) ) to heroku. I'm following this tutorial (see link below): https://wagtail.io/blog/deploying-wagtail-heroku/
But I have encountered one trouble during this tutorial: It's when I change the database between sqlite to PostgreSQL.
There is the trouble :
django.db.utils.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I am on mac os 10.13.3. Python with Anaconda.
There is what I have done :
Before this one, there no previous postgresql installed. I do not have any postgres server running (I don't know how I can check it but I am stuck at the first step of this tutorial...).
Thanks for your help! :)
The whole terminal response
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 83, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/migrations/executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/migrations/loader.py", line 52, in __init__
self.build_graph()
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/migrations/loader.py", line 209, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 254, in cursor
return self._cursor()
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 229, in _cursor
self.ensure_connection()
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 189, in connect
self.connection = self.get_new_connection(conn_params)
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 176, in get_new_connection
connection = Database.connect(**conn_params)
File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Upvotes: 1
Views: 1384
Reputation: 96
You need to create your Postgres database before you can connect to it The easiest way is to use Postico: https://eggerapps.at/postico/
Create the database in Postico (example db name "mysite"), then in your base.py settings you'd have something like:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mysite',
'USER': '', # e.g 'postgres'
'PASSWORD': '',
'HOST': '', # Set to empty string for localhost.
'PORT': '', # Set to empty string for default.
'CONN_MAX_AGE': 600, # number of seconds database connections should persist for
}
}
Don't forget that you'll need to run your migrations again to build all the tables. So from manage.py, you'd run makemigrations
and then migrate
.
Upvotes: 1
Reputation: 1451
If you don't have any PostgreSQL server running then the suggestion in the error message "Is the server running locally?" is pretty helpful! :)
Since you're on OS X, I recommend https://postgresapp.com as the easiest way to get started with PostgreSQL.
Note that, while there are good reasons to use the same setup in both places, it's possible to develop your project with SQLite locally, and use PostgreSQL on Heroku.
Upvotes: 1