2017-03-01 67 views
0

當我試圖運行我的Django項目到本地主機,我遇到了以下問題:無法連接運行的Django

^C(venv) tests-MacBook-Pro-2:hearinsights morganlai$ python manage.py runserver 
Performing system checks... 

System check identified no issues (0 silenced). 
Unhandled exception in thread started by <function wrapper at 0x103fc46e0> 
Traceback (most recent call last): 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper 
    fn(*args, **kwargs) 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run 
    self.check_migrations() 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 163, in check_migrations 
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS]) 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/site-packages/django/db/migrations/executor.py", line 20, in __init__ 
    self.loader = MigrationLoader(self.connection) 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/site-packages/django/db/migrations/loader.py", line 49, in __init__ 
    self.build_graph() 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/site-packages/django/db/migrations/loader.py", line 176, in build_graph 
    self.applied_migrations = recorder.applied_migrations() 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations 
    self.ensure_schema() 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/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/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/site-packages/django/db/backends/base/base.py", line 231, in cursor 
    cursor = self.make_debug_cursor(self._cursor()) 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/site-packages/django/db/backends/base/base.py", line 204, in _cursor 
    self.ensure_connection() 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection 
    self.connect() 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__ 
    six.reraise(dj_exc_type, dj_exc_value, traceback) 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection 
    self.connect() 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/site-packages/django/db/backends/base/base.py", line 171, in connect 
    self.connection = self.get_new_connection(conn_params) 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/site-packages/django/db/backends/postgresql/base.py", line 175, in get_new_connection 
    connection = Database.connect(**conn_params) 
    File "/Users/morganlai/Desktop/hearinsights-heap/venv/lib/python2.7/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? 

我試圖啓動和重新啓動Postgres數據庫這裏的操作說明:How to start PostgreSQL server on Mac OS X?

重新啓動服務器後,問題依然發生:

tests-MacBook-Pro-2:hearinsights morganlai$ pg_ctl -D /usr/local/var/postgres stop -s -m fast 
pg_ctl: PID file "/usr/local/var/postgres/postmaster.pid" does not exist 
Is server running? 
tests-MacBook-Pro-2:hearinsights morganlai$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start 
server starting 

,當我重新啓動我的Mac我會遇到這樣的問題,每一次並且該文章提供的解決方案通常在過去工作。由於這次不工作,我不知道這可能是一些其他問題。

+1

它似乎像Postgres沒有運行時,你開始你的Django項目 – haifzhan

+0

我按照指示重新啓動服務器,它仍然沒有工作... – YAL

+0

Postgres服務器有麻煩運行;看看[服務器日誌](http://stackoverflow.com/questions/2563494/where-are-the-postgresql-logs-on-mac-os-x)。看起來,這與Python無關。確保你可以先連接'psql'。 – 9000

回答

相關問題