我有一个烧瓶应用程序,我正在尝试转换成Django。在继承抽象基模型的其中一个模型中,它被提到为
__table_args__ = {'extend_existing': True}
请有人用一个小例子解释一下这在SQLAlchemy中的含义。
我已经读过几篇文章了,但是当我在Django上工作时,我对还没有完全理解。
https://hackersandslackers.com/manage-database-models-with-flask-sqlalchemy/ config.html
发布于 2021-12-13 04:30:36
当设置为True时,告诉该表已经存在于元数据中。此参数用于确定是否允许此表为其继承类添加新列,或者可以说是“扩展”。
例如,我有:
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.
此参数默认为“False”,通常不希望更改此设置。
https://stackoverflow.com/questions/57646511
复制相似问题