# 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()
Here is what the above code is Doing:
1. You’re creating a new instance of the Orders class.
2. You’re assigning the Dept_id field to the Department instance with the id of yourValueHere.
3. You’re saving the Orders instance.
You’re not assigning the Department instance to the Dept_id field. You’re assigning the id of the Department instance to the Dept_id field.
You need to do this:
Orders.Dept_id = Department.objects.get(id = yourValueHere)
Orders.save()