Reputation: 171
I am creating a table in database using flask sqlalchemy
In models.py,
Class User(model):
user_id = Column(Integer, primary_key=True)
du_id = Column(Integer)
name = Column (NVARCHAR(20))
#other fields...
In this table, when inserting new record, the user_id is created automatically.
How to save the user_id value in du_id field automatically when creating/inserting new record?
Thanks
Upvotes: 1
Views: 401
Reputation: 3407
You can use a hybrid attribute instead of a new column
class User(model):
user_id = Column(Integer, primary_key=True)
name = Column (NVARCHAR(20))
#other fields...
@hybrid_property
def length(self):
return self.user_id
Upvotes: 1