I was trying to update a row in SQLite DB from flask app using flask-sqlalchemy. I trying to do the same with python 3.6.8. But the row is not getting updated and also there is no exception of any sort. The problem is happening with the code in the put
method.
The Code
db = SQLAlchemy(app)
class MakeTemplate(Resource):
def __init__(self):
self.parser = reqparse.RequestParser()
def put(self):
self.parser = reqparse.RequestParser()
self.parser.add_argument('editProducte', type=str, required=True)
self.parser.add_argument('editData', required=True)
args = parser.parse_args()
editProducte = args["editProduct"]
new_json = args["editData"]
model_json = models.Template.query.filter_by(
product_name=editProducte).first()
model_json.json_template = "{'new' :\" test\" }"
model_json.update_date = datetime.datetime.utcnow()
db.session.commit()
return jsonify({"data": new_json})
I also tried this code which is mentioned in this stackoverflow Question
def put(self):
parser.add_argument('editInvoice', type=str, required=True)
parser.add_argument('editData', required=True)
args = parser.parse_args()
editInvoice = args["editInvoice"]
new_json = args["editData"]
rows_changed = models.Template.query.filter_by(
invoice_name=editInvoice).update(dict(json_template={}))
db.session.commit()
This the models.py where the model is defined
class Template(app.db.Model):
id = app.db.Column(app.db.Integer, primary_key=True)
created_date = app.db.Column(DATETIME, default=datetime.datetime.utcnow)
update_date = app.db.Column(DATETIME)
company = app.db.Column(VARCHAR)
invoice_name = app.db.Column(VARCHAR, nullable=False, unique=True)
image_location = app.db.Column(VARCHAR, nullable=True)
json_template = app.db.Column(JSON, nullable=False)
def __repr__(self):
return '<User %r>' % self.company
Could someone please tell me the possible cause and solution? If I've missed out anything, over- or under-emphasized a specific point, let me know in the comments.