Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

django foreign key error Cannot assign must be a instance

# This error is because you're trying to assign an instance.id instead of 
# the instance itself. If its a foreign key field you assigned the instance i.e.
yourTable.yourCol = relatedTable.objects.get(relatedTableColumn = yourColValue)
#-or-
Orders.Dept_id = Department.objects.get(id = yourValueHere)
Orders.save()
 
PREVIOUS NEXT
Tagged: #django #foreign #key #error #Cannot #assign #instance
ADD COMMENT
Topic
Name
5+5 =