[英]How to create an identity column not being a primary key with SQLAlchemy?
How do I create an identity column in SQLAlchemy, auto-incrementing itself and not being the primary key? 如何在SQLAlchemy中创建一个标识列,使其自身自动递增而不是主键?
I'm using Postgres. 我正在使用Postgres。
Thanks, 谢谢,
Yann 晏
Something like this should work. 这样的事情应该起作用。
table_sequence = Sequence('table_id_seq', start=1)
class MyTable(Base):
__tablename__ = 'mytable'
id = Column(Integer, table_sequence, server_default=table_sequence.next_value())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.