鍍金池/ 問答/Python  數(shù)據(jù)庫/ UserWarning: Neither SQLALCHEMY_DATABASE

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:".'
            )

怎么解決這個問題呢?

回答
編輯回答
巷尾

拼寫錯誤。SQLALCHEMY_DATABASES_URI是錯的。SQLALCHEMY_DATABASE_URI才是對的。

2017年5月25日 11:05
編輯回答
枕邊人

犯了個低級錯誤,

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

DATABASE寫成了DATABASES

2017年8月11日 02:45