Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set

Issue

I’m trying to make a simple todo app with flask and sqlalchemy.

I have the code below:

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHERMY_DATABASE_URI'] = 'sqlite:////Users/umutcan/Desktop/pythonProject/To-Do app/todo.db'
db = SQLAlchemy(app)
class ToDo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(80))
    complete = db.Column(db.Boolean)
if __name__ == "__main__":
    db.create_all()
    app.run(debug=True)

I don’t understand why I’m getting this output:

PS C:\Users\umutcan\Desktop\pythonProject\To-Do app> & C:/Anaconda3/python.exe "c:/Users/umutcan/Desktop/pythonProject/To-Do app/todo.py"
C:\Anaconda3\lib\site-packages\flask_sqlalchemy\__init__.py:851: UserWarning: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memory:".
  warnings.warn(
C:\Anaconda3\lib\site-packages\flask_sqlalchemy\__init__.py:872: 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(
 * Serving Flask app "todo" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with windowsapi reloader
C:\Anaconda3\lib\site-packages\flask_sqlalchemy\__init__.py:851: UserWarning: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memory:".
  warnings.warn(
C:\Anaconda3\lib\site-packages\flask_sqlalchemy\__init__.py:872: 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(
 * Debugger is active!
 * Debugger PIN: 240-804-640
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

What can I do in order to solve it?

Solution

Your app seems to be running as it should. You just have to set the variables in order to make flask-sqlalchemy work.

You have mispelled SQLALCHEMY_DATABASE_URI. So your code would actually be:

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////Users/umutcan/Desktop/pythonProject/To-Do app/todo.db'

To disable warnings about SQLALCHEMY_TRACK_MODIFICATIONS you have to set it to False:

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

Answered By – Maicon Mauricio

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published