SQLAlchemy "AttributeError: 'str' object has no attribute 'c'"
In your UserPermission
class, you are using the wrong dunder attribute:
__table__ = 'userPermissions'
Should be:
__tablename__ = 'userPermissions'
Sqlalchemy is trying to treat the string 'userPermissions'
as a Table
object.
Regarding the difference between __table__
and __tablename__
, most cases will only require declaring __tablename__ = "stringvalue"
on a declarative class. It signals that the object should reference a table of that name, and SQLAlchemy can handle the construction of that Table
object internally.
Declaring a __table__
on the object instead signals to SQLAlchemy that you want to take control of the construction of the Table
that the ORM class represents. This would be most useful if you already have a reference to the table from some other means like table reflection. More reading here.
class UserPermission(Base):
__table__ = 'userPermissions'
here should be :
class UserPermission(Base):
__tablename__ = 'userPermissions'