mysql database uri_UserWarning: Neither SQLALCHEMY_DATABASE_URI...

flask_sqlalchemy报错:

F:\shop\myshop\lib\site-packages\flask_sqlalchemy\__init__.py:774: UserWarning: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memory:".

'Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. '

我按照文档上的改成mysql+pymysql后还是报错

modles.py

from datetime import datetime

from flask import Flask

from flask_sqlalchemy import SQLAlchemy

import pymysql

app = Flask(__name__)

app.config['SQLALCHEMY_DATABASES_URI'] = 'mysql+pymysql://root:admin@127.0.0.1:3306/movie'

#app.config['SQLALCHEMY_BINDS'] = 'mysql+pymysql://root:admin@127.0.0.1:3306/movie'

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True

db = SQLAlchemy(app)

flask_sqlalchemy/__init__.py:

def init_app(self, app):

"""This callback can be used to initialize an application for the

use with this database setup. Never use a database in the context

of an application not initialized that way or connections will

leak.

"""

if (

'SQLALCHEMY_DATABASE_URI' not in app.config and

'SQLALCHEMY_BINDS' not in app.config

):

warnings.warn(

'Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. '

'Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memory:".'

)

怎么解决这个问题呢?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值