All the steps seem to be working fine but when I try to run heroku run python manage.py migrate
it gives me an error saying Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?
. I can't figure this part out. Do I need to change the settings of my postgresql database? But I have already existing data on my postgresql database.How will they get migrated into heroku if I change my database settings.
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'music',
'USER': '**',
'PASSWORD': '**',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
full error traceback
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.4/site- packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.4/sitepackages/django/core/management/_
_init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.4/site- packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.4/site- packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.4/sitepackages/django/core/management/commands/migrate.py", line 93, in handle
executor = MigrationExecutor(connection,self.migration_progress_callback)
File "/app/.heroku/python/lib/python3.4/site- packages/django/db/migrations/exe
cutor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "/app/.heroku/python/lib/python3.4/site- packages/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/app/.heroku/python/lib/python3.4/site- packages/django/db/migrations/loader.py", line 180, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/backends/base/base.py", line 164, in cursor
cursor = self.make_cursor(self._cursor())
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/backends/base/base.py", line 135, in _cursor
self.ensure_connection()
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/app/.heroku/python/lib/python3.4/site- packages/django/db/utils.py", line 97, in __exit__six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/app/.heroku/python/lib/python3.4/sitepackages/django/utils/six.py", line 658, in reraise
raise value.with_traceback(tb)
File "/app/.heroku/python/lib/python3.4/site- packages/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/app/.heroku/python/lib/python3.4/site- packages/django/db/backends/base/base.py", line 119, in connect
self.connection = self.get_new_connection(conn_params)
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection
connection = Database.connect(**conn_params)
File "/app/.heroku/python/lib/python3.4/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
The db server isn't running on the local machine on Heroku, of course. You should follow the documentation and use the dj-database-url library to set the db location automatically from the environment.