[Answered ]-Incorrect value – python to model in Django

2👍

You’re trying to insert the string "id", rather than the value of the variable id.

It should be:

cursor.execute(sql, (id,))

Of course, there’s no reason to be using raw SQL for this at all.

0👍

As Daniel said, “there’s no reason to be using raw SQL.” Instead, you should make use of Django’s model syntax for inserting new items into the datebase, like so:

e = Evento.objects.create(id_unidad=id)

This one line can replace everything below print type(id). More importantly, using Django’s Models for database manipulation gives you SQL injection protection for free.

Leave a comment