在heroku上部署时,Django 1.8 postgresql数据库设置错误

时间:2015-06-23 23:32:55

标签: python django postgresql heroku django-database

所有步骤似乎都运行良好但是当我尝试运行heroku run python manage.py migrate时,它会给我一个错误Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?。我无法理解这一部分。我是否需要更改postgresql数据库的设置?但我已经在postgresql数据库上存在了数据。如果我更改数据库设置,他们将如何迁移到heroku。

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?

1 个答案:

答案 0 :(得分:0)

当然,数据库服务器并不在Heroku上的本地计算机上运行。您应该遵循documentation并使用dj-database-url库从环境中自动设置db位置。