I'm new to Flask and Python and I don't understand why it gives me this error:
Traceback (most recent call last):
File "C:\Users\Lucía\Documents\TFG\herfontsistemas-app\herfontsistemas-back\index.py", line 6, in <module>
db.create_all()
File "C:\Users\Lucía\Documents\TFG\herfontsistemas-app\herfontsistemas-back\env\lib\site-packages\flask_sqlalchemy\extension.py", line 868, in create_all
self._call_for_binds(bind_key, "create_all")
File "C:\Users\Lucía\Documents\TFG\herfontsistemas-app\herfontsistemas-back\env\lib\site-packages\flask_sqlalchemy\extension.py", line 846, in _call_for_binds
raise sa.exc.UnboundExecutionError(message) from None
sqlalchemy.exc.UnboundExecutionError: 'SQLALCHEMY_DATABASE_URI' config is not set. Bind key 'None' is not in 'SQLALCHEMY_BINDS' config.
This is my app.py:
from flask import Flask
from routes.contacts import contacts
from flask_sqlalchemy import SQLAlchemy
app=Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']='mysql://root:lucia@localhost/herfontsistemasdb'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=False
SQLAlchemy(app)
app.register_blueprint(contacts)
This is my index.py:
from app import app
from utils.db import db
#Cuando arranque la aplicacion creará las tablas dee contact.py
with app.app_context():
db.create_all()
if __name__=="__main__":
app.run(debug=True)
This is my contact.py:
from utils.db import db
class Contact(db.Model):
id = db.Column(db.Integer, primary_key=True)
nombreCompleto = db.Column(db.String(100))
email = db.Column(db.String(100))
telefono = db.Column(db.String(100))
def __init__(self,nombreCompleto,email,telefono):
self.nombreCompleto=nombreCompleto
self.email=email
self.telefono=telefono
enter code here
This is my db.py:
from flask_sqlalchemy import SQLAlchemy
db=SQLAlchemy()