带有主键的默认值 sqlalchemy

Mar*_*rte 4 python sqlalchemy python-3.x

我有以下课程

class Comision(Base):
    __tablename__ = 'comision'

    id = Column(Integer, primary_key=True)
    key = Column(Integer, default=process())
Run Code Online (Sandbox Code Playgroud)

在列键中,我有 def process,我需要使用该表的主键进行一些操作,可以像参数一样传递它吗?

eme*_*eth 6

尝试

key = Column(Integer, default=process)
Run Code Online (Sandbox Code Playgroud)

或者

key = Column(Integer, default=lambda:process())
Run Code Online (Sandbox Code Playgroud)

定义为key = Column(Integer, default=process()),仅在定义process()类时调用一次。Comision

Context-Sensitive Default Functions有关更多详细信息,请参阅http://docs.sqlalchemy.org/en/rel_0_8/core/defaults.html 。