Reputation: 1639
I need to build a dictionary which would have Django Models as keys but I get this error on a default made model:
TypeError: Model instances without primary key value are unhashable
yet, Django documentation says that it takes care of building id as default primary key.
So why do I get this error?
Upvotes: 0
Views: 640
Reputation: 77912
Note that the error message explicitely mentions an empty pk value. IOW: you have to save the model instance first, serial (auto) id fields only get their values when the record is inserted in the table.
Upvotes: 4