小编Ovi*_*ron的帖子

Flask-SQLAlchemy Postgres 错误 - 无法连接到服务器:连接被拒绝 (0x0000274D/10061)

这是我当前的初始化文件,我已经在 models.py 上创建了数据库模型,但我认为我对此没有任何问题。每当我“db.create_all()”时,我都无法创建数据库表......它给了我错误,我在下面发布了。

  • 我安装了 psycopg2。
  • 我尝试在我的database_uri链接上添加“localhost:5432”,但这也不起作用。
  • 我进入我的 postgres 配置文件并将“listen_addresses”从“*”更改为“::1, 127.0.0.1”
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)

app.config['SECRET_KEY'] = 'mysecretkey'

# DATABASE CONFIGS ---------------------------------------------------------------------------
db = SQLAlchemy(app) 

ENV = 'dev'

if ENV == 'dev':
    app.debug = True
    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:123456@localhost/flaskqna'
else:
    app.debug = False
    app.config['SQLALCHEMY_DATABASE_URI'] = ''

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)

# DATABASE CONFIGS ---------------------------------------------------------------------------

from flaskqna import routes
Run Code Online (Sandbox Code Playgroud)

错误

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused (0x0000274D/10061)
        Is the server running on host "localhost" (::1) …
Run Code Online (Sandbox Code Playgroud)

python postgresql sqlalchemy flask python-3.x

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

flask ×1

postgresql ×1

python ×1

python-3.x ×1

sqlalchemy ×1