suffa
suffa

Reputation: 3806

Django get method is yielding an error

I'm following a Django book (Django 1.0 Web Site Development). I'm finding that the book, although straight forward and easy to read, leaves out small details. However, this error that I'm getting, I have not been able to find a solution online. Thanks for any help.

Below, I added the Tag class to my models.py file.

from django.db import models
from django.contrib.auth.models import User


class Link(models.Model):
    url = models.URLField(unique=True)



class Bookmark(models.Model):
    title = models.CharField(max_length=200)
    user = models.ForeignKey(User)
    link = models.ForeignKey(Link)



class Tag(models.Model):
    name = models.CharField(max_length=64, unique=True)
    bookmarks = models.ManyToManyField(Bookmark)

Then I attempt to run the following code at the python shell:

from bookmarks.models.import *
bookmark = Bookmark.objects.get(id=1)

As a result, I get the following error:

Traceback (most recent call last):
File "(console)", line 1, in (module)
File "c:\Python27\lib\site\-packages\django\db\models\manager.py", line 132, in get
   return self.get_query_set().get(*args, **kwargs)
File "c:\Python27\lib\site-packages\django\db\models\query.py", line 349, in get
   % self.model._meta.object_name)
DoesNotExist: Bookmark matching query does not exist.

Upvotes: 0

Views: 87

Answers (2)

koniiiik
koniiiik

Reputation: 4382

The error means just what it says. DoesNotExist is raised by QuerySet.get() if there is no object in the database that would match the conditions given to the QuerySet. In this case it means there is no Bookmark object in the database with an ID equal to 1.

Upvotes: 1

Praveen Gollakota
Praveen Gollakota

Reputation: 38980

Did you add any data in the Bookmark table yet? DoesNotExist is raised by get if there is no record corresponding to your query. i.e. if there is no record corresponding to id=1.

Upvotes: 1

Related Questions