I am learning sqlalchemy
.
Here is my initial code :
user.py
from sqlalchemy import Column, Integer, Sequence, String
fr
declarative_base() is a factory function that constructs a base class for declarative class definitions (which is assigned to the Base
variable in your example). The one you created in user.py is associated with the User
model, while the other one (in main.py) is a different class and doesn't know anything about your models, that's why the Base.metadata.create_all()
call didn't create the table. You need to import Base
from user.py
from user import User, Base
instead of creating a new Base
class in main.py.