Search code examples
pythonflasksqlalchemyflask-sqlalchemy

Unexpected Warnings about SQLALCHEMY_DATABASE_URI, SQLALCHEMY_BINDS and SQLALCHEMY_TRACK_MODIFICATIONS


I am making an app with a cache, and it works fine. But the problem is I keep getting these warnings when I shouldn't get them. These are the warnings:

C:\Users\user\PycharmProjects\meon-dashboard\venv\lib\site-packages\flask_sqlalchemy\__init__.py:812: UserWarning: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memory:".
  warnings.warn(
C:\Users\user\PycharmProjects\meon-dashboard\venv\lib\site-packages\flask_sqlalchemy\__init__.py:833: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
  warnings.warn(FSADeprecationWarning(

And I have them set as you can see from this piece of code:

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///configs/cache.sqlite3"

Can someone tell me why I am getting these warnings and how to make them not appear?

(I tried setting app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] as True as well but it didnt work.)


Solution

  • Instead of:

    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///configs/cache.sqlite3"
    

    It should be:

    app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///configs/cache.sqlite3"
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    

    You can read more about it here:

    https://flask-sqlalchemy.palletsprojects.com/en/2.x/signals/

    Also, SQLALCHEMY_TRACK_MODIFICATIONS will be set to False by default, starting from version 3.0.0 (unreleased):

    https://flask-sqlalchemy.palletsprojects.com/en/master/changelog/#version-3-0-0

    As of this writing, current version is 2.4.4:

    https://flask-sqlalchemy.palletsprojects.com/en/master/changelog/#version-2-4-4