I have a model called Service where I have an object named Service1. I got the following at the shell:
$ obj, created = Service.objects.get_or_create(name=u'Service1')
$ obj
<Service: Service1>
$ obj.id
3
$ created
False
$ Service.objects.all()
[<Service: Service1>]
$ Service.objects.first().id
1
I checked the database and there is only one Service object which is the Service with id=1. Why is get_or_create
retrieving an object that doesn't even exist?
The problem was caching. I was using a new dump of the database, but I forgot invalidating the cache. Django was retrieving an object that does't exist anymore but would be found on the older database .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.