这是我当前的init文件,我已经在我的models.py上创建了数据库模型,但是我认为这没有任何问题。每当我“ db.create_all()”时,我都无法创建数据库表...这给了我错误,我在下面发布了。
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
错误
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?
答案 0 :(得分:2)
我陷入了这个完全相同的问题,对我有用的是显式使用端口5433。
postgresql://postgres:123456@localhost:5433/flaskqna
在打开SQL Shell(psql)并在第一个提示中输入 5432 ,然后在第二个提示中输入数据库名称后,我意识到了这一点。您的情况是 flaskqna 。端口 5433 出现在其中。
您似乎已恢复为sqlite,但请尝试一下