title: Django - matching query does not exist
body: <p>I'm working on a Django project and I'm getting this error, "State matching query does not exist." why is this happening? the state is in the model store, can you explain me this error and how to solve it?</p>
  
  <p>Thanks. 
  Views: </p>
  
  <pre><code>def Test(request):
      stores = Store.objects.all()
  
      data = []
  
      for store in stores:
          data.append({
              'id': store.id,
              'name': store.name,
              'address': store.address,
              'state': store.state,
          })
  
      return HttpResponse(json.dumps(data), 'application/json')
  </code></pre>
  
  <p>Models:</p>
  
  <pre><code>class State(models.Model):
      name = models.CharField(max_length=255)
      shortname = models.CharField(max_length=100)
  
  
      def __unicode__(self):
          return self.name
  
  
  class City(models.Model):
      name = models.CharField(max_length=255)
      state = models.ForeignKey(State)
  
      def __unicode__(self):
          return self.name
  
  
  class Store(models.Model):
      name = models.CharField(max_length=255, null=True, blank=True)
      address = models.CharField(max_length=255, blank=True, null=True)
      lon = models.FloatField(blank=True, null=True)
      lat = models.FloatField(blank=True, null=True)
      state = models.ForeignKey(State)
      city = models.ForeignKey(City)
  
  
      def __unicode__(self):
          return self.name
  </code></pre>
  
  <p>Traceback: </p>
  
  <blockquote>
    <p>Environment:</p>
    
    <p>Request Method: GET Request URL: <a href="http://127.o.o.1:8000/posts/Test/" rel="nofollow noreferrer">http://127.o.o.1:8000/posts/Test/</a></p>
    
    <p>Django Version: 1.7.1 Python Version: 2.7.6 Installed Applications:
    ('django.contrib.admin',  'django.contrib.auth', 
    'django.contrib.contenttypes',  'django.contrib.sessions', 
    'django.contrib.messages',  'django.contrib.staticfiles',  'clients', 
    'cobrands',  'core',  'posts',  'bootstrapform',  'rest_framework')
    Installed Middleware:
    ('django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware')</p>
    
    <p>Traceback: File
    "/home/tabzz/c-dev/local/lib/python2.7/site-packages/django/core/handlers/base.py"
    in get_response
      111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/tabzz/c/posts/views.py" in Test
      34.             'state': store.state, File "/home/tabzz/c-dev/local/lib/python2.7/site-packages/django/db/models/fields/related.py"
    in <strong>get</strong>
      572.                 rel_obj = qs.get() File "/home/tabzz/c-dev/local/lib/python2.7/site-packages/django/db/models/query.py"
    in get
      357.                 self.model._meta.object_name)</p>
    
    <p>Exception Type: DoesNotExist at /posts/Test/ Exception Value: State
    matching query does not exist.</p>
  </blockquote>