SQLAlchemy查询将id标记为nu

2024-09-22 20:34:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用SQLAlchemy将一行插入表中。表的定义如下:

class MyTable():
    __table__ = "my_table"
    id = Column(BigInteger, primary_key=True)
    stuff1 = Column(Numeric)

以下是炼金术:

^{pr2}$

下面是它生成的查询:

INSERT INTO my_table (id, stuff1) VALUES (null, 100)

我得到一个错误:

IntegrityError('(psycopg2.IntegrityError) null value in column \"id\" violates not-null constraint

主键是自动生成的,因为它是自动生成的。但似乎我必须手动对其应用一个序列?我做错什么了?在


Tags: keyidtrue定义sqlalchemymymytabletable