我在我的项目中使用sqlalchemy。当我在sqlalchemy模型中修改json列时,它一点也没有改变。这就是我的代码:
class Order(DB.Model):
uid = DB.Column(DB.Integer, primary_key=True, index=True, unique=True)
status_uid = DB.Column( DB.Integer, default=1 )
json_data = DB.Column( DB.JSON, nullable=True )
orderobj = Order(json_data{'key':'old value'})
DB.session.add( orderobj )
# That is work fine
DB.session.commit()
# Trying to update
orderobj = Order.query.filter_by( status_uid=1 ).first()
orderobj.json_data['key'] = 'new value'
print(orderobj.json_data['key']) # -> 'old value'
DB.session.commit()
print(orderobj.json_data['key']) # -> 'old value'
1条答案
按热度按时间slhcrj9b1#