I am trying to reflect a table called 'cars' from a sqlite database called 'mydb.db' to use in a flask API but I get some errors when doing it:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import MetaData, create_engine
from sqlalchemy import Table
app = Flask(__name__)
engine = create_engine("sqlite:////...path.../mydb.db")
metadata = MetaData(engine, reflect=True)
Cars = Table('cars', metadata, autoload=True, autoload_with=engine)
db = SQLAlchemy(app)
car1 = Cars(ID_name = 'asd1' , name ='Roger' , state='done' )
db.session.add(car1)
db.session.commit
if __name__ == '__main__':
app.run()
But I get the following error 'TypeError: 'Table' object is not callable'
How Can I fix it?
pd. My db has a primarykey which is 'ID_name'
Aucun commentaire:
Enregistrer un commentaire