最近在用FLASK开发一个网站,从github上面clone了一个小例子,用的数据库是postgresql,当数据库服务没有打开时,会报以下错误():
Traceback (most recent call last):
File "/root/workspace_aptana/flask/flask-bootstrap/app.py", line 86, in <module>
db.create_all()
File "/usr/lib/python2.6/site-packages/flask_sqlalchemy.py", line 822, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/usr/lib/python2.6/site-packages/flask_sqlalchemy.py", line 814, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), tables=tables)
File "/usr/lib64/python2.6/site-packages/sqlalchemy/schema.py", line 2783, in create_all
tables=tables)
File "/usr/lib64/python2.6/site-packages/sqlalchemy/engine/base.py", line 1478, in _run_visitor
with self._optional_conn_ctx_manager(connection) as conn:
File "/usr/lib64/python2.6/contextlib.py", line 16, in __enter__
return self.gen.next()
File "/usr/lib64/python2.6/site-packages/sqlalchemy/engine/base.py", line 1471, in _optional_conn_ctx_manager
with self.contextual_connect() as conn:
File "/usr/lib64/python2.6/site-packages/sqlalchemy/engine/base.py", line 1661, in contextual_connect
self.pool.connect(),
File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 272, in connect
return _ConnectionFairy(self).checkout()
File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 425, in __init__
rec = self._connection_record = pool._do_get()
File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 777, in _do_get
con = self._create_connection()
File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 225, in _create_connection
return _ConnectionRecord(self)
File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 318, in __init__
self.connection = self.__connect()
File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 368, in __connect
connection = self.__pool._creator()
File "/usr/lib64/python2.6/site-packages/sqlalchemy/engine/strategies.py", line 80, in connect
return dialect.connect(*cargs, **cparams)
File "/usr/lib64/python2.6/site-packages/sqlalchemy/engine/default.py", line 283, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/usr/lib64/python2.6/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
sqlalchemy.exc.OperationalError: (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?
None None
这时只需要检查一下postgresql的服务有没有打开,
service postgresql status,
如果没有打开,打开一下就行了,
service postgresql start