我在项目中使用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'
答案 0 :(得分:0)
php artisan serve