我是 SQLAlchmey 的新手,我正在尝试实现以下对象/数据库表结构(也使用 alembic):
class BaseConfig(Base):
pk = Column(Integer, primary_key=True)
name = Column(Unicode(150), nullable=False, unique=True)
...
# Lots of other general columns, such as description, display_name, creation time etc.
我希望所有其他配置类都从中继承预定义的列:
class A(BaseConfig):
__tablename__ = "A"
column1 = Column...
column2 = Column...
class B(BaseConfig):
__tablename__ = "B"
column1 = Column...
column2 = Column...
BaseConfig表不是真正的表,它只是一个保存公共列的类。除此之外 - A 和 B 之间没有任何关系,也不需要共享 pk 等。似乎使用“ polymorphic_union ”在这里也无关紧要。
通过尝试运行 alembic autogenerate 我得到了 BaseConfig 没有表映射类的错误 - 这是真的,我真的没有理由将“多态联合”选项添加到 BaseConfig,因为这个类是通用的. 有什么建议么?(在 Django with south 中,这是开箱即用的,但在这里似乎不容易支持这种行为)。
谢谢,李