Issue
I have a flask application which I'm trying to convert into Django. In one of the models which inherit an abstract base model, it is mentioned as
__table_args__ = {'extend_existing': True}
Can someone please explain what this means in SQLAlchemy with a small example.
I have gone through few articles but as I worked on Django and new to Flask-SQLAlchemy I couldn't understand it properly.
https://hackersandslackers.com/manage-database-models-with-flask-sqlalchemy/ https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/table_config.html
Solution
This parameter is to determine wheter this table is allowed to add new columns for its inheriting classes, or to 'extend' so to speak.
For example, I have:
class User(Base):
__table_args__ = {'extend_existing': True}
attr1 = Column(String)
attr2 = Column(Integer)
class ChildUser(User):
attr3 = Column(Integer) # this will allow this column to 'extend' the parent attriubtes.
This parameter is default to 'False', and normally you wouldn't want to change this setting.
Answered By - Jinghui Niu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.