SQLAlchemy – what is declarative_base

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)