我有一个没有主键
的表。而且我真的不想将此约束应用于此表。
在SQLAlchemy中,我定义了表类:
class SomeTable(Base):
__table__ = Table('SomeTable', meta, autoload=True, autoload_with=engine)
当我尝试查询这个表时,我得到了:
ArgumentError: Mapper Mapper|SomeTable|SomeTable could not assemble any primary key columns for mapped table 'SomeTable'.
如何失去每张表必须有主键的约束?
最佳答案
据我所知,在 SQL Alchemy 中规避主键约束的方法只有一种——它是将特定列或列作为主键映射到您的表中,即使它们本身不是主键。 http://docs.sqlalchemy.org/en/latest/faq/ormconfiguration.html#how-do-i-map-a-table-that-has-no-primary-key .
关于python - 如何使用 SQLAlchemy 定义没有主键的表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34283259/