Django – Cannot force an update in save() with no primary key.

If all debugging steps lead you nowhere with this problem, make sure you are not deferring any fields on your queryset prior to an insert attempt.

For example, I was calling save() on a recently copied object which initially had a deferred field.

Example:

obj = Object.objects.defer('foo')[0]

<a href="http://obj.id">obj.id</a> = None
obj.save() # triggers error

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s