I have a python script app.py using Flask and SQLAlchemy to make a web application.
I have a table in the app.py script
class NutritionConsumed(db.Model):
__tablename__ = 'nutritionconsumed'
id = db.Column(db.Integer, primary_key=True)
date = db.Column(db.DateTime, nullable=False )
item = db.Column(db.String(200), nullable=False)
in the same folder I have my sqlite database 'test.db'. Running in browser everything works fine and I can read and display data from my tables.
However, how do I access this database in the Python shell terminal?
When starting python in the same directory as my web app is located, if I run
>>> nutritionconsumed.query.all()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'nutritionconsumed' is not defined
but in my test.db I do have a nutritionconsumed table.
NutritionConsumednotnutritionconsumednutritionconsumed is not definedmeans that the variablenutritionconsumeddoes not exist.