sách gpt4 ai đã đi

python - Flask-SQLAlchemy Postgres 错误 - 无法连接到服务器 : Connection refused (0x0000274D/10061)

In lại 作者:行者123 更新时间:2023-12-05 02:06:00 26 4
mua khóa gpt4 Nike

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

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

ứng dụng = Flask(__tên__)

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'
khác:
app.debug = False
app.config['SQLALCHEMY_DATABASE_URI'] = ''

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)

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

from flaskqna import routes

sai lầm

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?

1 Câu trả lời

我被困在这个完全相同的问题上,对我有用的是明确使用端口 5433。

postgresql://postgres:123456@localhost:5433/flaskqna

我在打开 SQL Shell (psql) 并在第一次提示中输入 5432 并在第二次提示中输入我的数据库名称后意识到了这一点。在您的情况下,它将是 flaskqna. 5433 端口出现在那里。

看起来你已经恢复到 sqlite,但试一试

关于python - Flask-SQLAlchemy Postgres 错误 - 无法连接到服务器 : Connection refused (0x0000274D/10061),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63044935/

26 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com