hello iam trying to get a currnet_user information in my views
and i include from users.models import *
then in my code return return current_user;
<
This depends on what you want to do, are you trying to:
In the first case using your example above, try running the following line before defining your classes:
db.metadata.clear()
The reason is the first time you declare a SQLAlchemy Mapping by defining a python class, the definition of the class is saved to the metadata object, in order to prevent conflicts caused by multiple definitions being mapped to the same table.
When you call the clear()
method you clear all the table definitions held in memory by the Metadata object, which allows you to declare them again.
In the second case when you're just restarting the app I would write a test to see if the table already exists using the reflect method:
db.metadata.reflect(engine=engine)
Where engine is your db connection created using create_engine()
, and see if your tables already exist and only define the class if the table is undefined.