[Answered ]-SQL update query no such column in django

2👍

Fix to this particular problem

 cursor.execute('UPDATE wallet_wallet SET amount= %s WHERE username=%s'  ,  (self.amount, self.username))

Note how the % changes to , this uses parameter binding and also protects you to some extend from SQL injection.

The real solution.

Don’t use raw sql here.

  def add_money(self, money):
        self.amount = self.amount + int(money)
        self.save()

Really, there isn’t a need for it. just call save(). to make it even more compact you don’t even need the add_money method at all!! Refer to the F expression approach I mentioned in your previous question.

👤e4c5

Leave a comment