📜  django外键错误无法分配必须是实例 - Python代码示例

📅  最后修改于: 2022-03-11 14:45:06.598000             🧑  作者: Mango

代码示例1
# 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()