简体   繁体   English

如何使用SQLAlchemy创建一个不是主键的标识列?

[英]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.

相关问题 在 sqlalchemy 上为 sql server 创建列不是主键而是身份 - create column not primary key but identity on sqlalchemy for sql server SQLAlchemy:如何在具有IDENTITY主键列的Sybase数据库表中插入新行? - Sqlalchemy: How to insert a new row into a Sybase database table which has an IDENTITY primary key column? 如何在 SQLAlchemy 中创建一个以 Interval 作为主键的表? - How to create a table with Interval as primary key in SQLAlchemy? 如何创建一个sqlalchemy列,其默认值等于主键? - How can I create a sqlalchemy column whose default is to be equal to the primary key? 是否有可能让sqlalchemy创建一个带有整数部分的复合主键而不使其成为IDENTITY类型? - Is it possible to get sqlalchemy to create a composite primary key with an integer part without making it an IDENTITY type? 使用python sqlalchemy,如何定义多列主键 - with python sqlalchemy, how do define multiple-column primary key SQLAlchemy:可以声明性地将列声明为主键吗? - SQLAlchemy: Possible to declare a column as primary key declaratively? SQLAlchemy:创建由另一个复合主键组成的复合主键 - SQLAlchemy: create a composite primary key made of another composite primary key SQLAlchemy不仅通过主键从身份映射中获取项目 - SQLAlchemy get items from the identity map not only by primary key 如何防止使用相同值创建新 SQLAlchemy 对象的 UUID 主键 - How to prevent UUID primary key for new SQLAlchemy objects being created with the same value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM