Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default value with primary key sqlalchemy

I've the following class

class Comision(Base):
    __tablename__ = 'comision'

    id = Column(Integer, primary_key=True)
    key = Column(Integer, default=process())

in the column key i've the def process and i need to make some operations with the primary key of that table, it is possible to pass it like argument?

like image 560
Marco Herrarte Avatar asked Oct 26 '25 11:10

Marco Herrarte


1 Answers

Try

key = Column(Integer, default=process)

or

key = Column(Integer, default=lambda:process())

Defined as key = Column(Integer, default=process()), process() is called once only when class Comision is defined.

Take a look at Context-Sensitive Default Functions in http://docs.sqlalchemy.org/en/rel_0_8/core/defaults.html for more detail.

like image 74
emeth Avatar answered Oct 28 '25 01:10

emeth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!