[Fixed]-Django – Cannot assign, must be a instance

1πŸ‘

βœ…

The problem is your custom constructor for Child. When the ORM is trying to retrieve results, the overridden constructor prevents the ORM from passing in the column values to instantiate the instance properly. In other words, the ORM is trying to pass in the values in the column-specified order, e.g.,

 Child(id, date_created, parent)

while the custom constructor expects values to be passed in the following order:

 Child(parent, . . .)

To resolve this issue, remove your custom constructor and use

 instance = Child(parent=parent)

whenever you want to initialize a child with a parent.

Leave a comment