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
When set to True, tells that table is already present in the Metadata. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With