当我执行“object_name.objects.get(id=1)”时出现错误。早些时候,当 id=1 时我也收到了这个错误,但是当 id=2 时它返回了对象。然后我删除了我所做的所有条目,希望它从 id=1 开始,但现在它给出了错误。
有人可以解释为什么会发生这种情况,我该怎么办?
>>> from course.models import Course, Content
>>> Course.objects.get(id=1)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/vagrant/edu-venv/local/lib/python2.7/site-packages/django/db/models /manager.py", line 143, in get
return self.get_query_set().get(*args, **kwargs)
File "/home/vagrant/edu-venv/local/lib/python2.7/site-packages/django/db/models /query.py", line 389, in get
(self.model._meta.object_name, kwargs))
DoesNotExist: Course matching query does not exist. Lookup parameters were {'id': 1}
此外 object_name.object.all() 给出了我输入的所有内容
>>> Course.objects.all()
[<Course: JAVA>, <Course: HTML5>]