title: Django: Query returns different results in management command
body: <p>I have a django application with a model named <code>TestCase</code>. There are 9 instances of the model currently stored in the DB, which I can see by running <code>TestCase.objects.all()</code> in the shell, and they're also being displayed correctly in my views.</p>
  
  <p>However, in a management command I'm running, the same query (<code>TestCase.objects.all()</code>) consistently returns an empty list instead. I have imported the model correctly, and the management command is even able to add entries to the database without any problem, so reading back from the database shouldn't be a problem.</p>
  
  <p>Any ideas on what could be causing this?</p>
  
  <p>Some context: The django app is a frontend to display and manage testcases. The management command reads in the results from the test into the DB. I need to access the DB in the management command to incorporate test runs into the app - if a testcase provides a test run (an integer) it is used, but if it does not, then the command sets the test run to one plus the max test run present in the app already - this is where I need to access the DB (using something like <code>TestCase.objects.all().aggregate(Max('test_run'))</code>).</p>
  
  <p>I'm using Django 1.4.</p>
  
  <p>This is the management command:</p>
  
  <pre><code>from django.core.management.base import NoArgsCommand
  from django.core.management.base import AppCommand, CommandError
  from mainapp.models import TestCase
  from django.utils import timezone
  from django.db.utils import IntegrityError
  from django.conf import settings
  from django.core import management
  from django.db.models import Max 
  
  import cPickle
  import errno
  
  class Command(NoArgsCommand):
    def handle_noargs(self, **options):
      management.call_command('reset', 'mainapp', interactive=False) 
      print "ALL: %s" % TestCase.objects.all()
      self.traverse()
  
    def traverse(self):
      ...
  </code></pre>
  
  <p>the output is <code>ALL: []</code>. I've omitted the source of the <code>traverse()</code> method, but the problem is visible before that, so it shouldn't impact anything.</p>
  
  <p>Here's the output from the shell showing the instances in the DB:</p>
  
  <pre><code>[as@as-mac  ui]$ pm shell
  Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
  [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  (InteractiveConsole)
  &gt;&gt;&gt; from mainapp.models import TestCase
  &gt;&gt;&gt; TestCase.objects.all()
  [&lt;TestCase: internet explorer 8 on WIN7 at https://www.google.com/ &gt;, &lt;TestCase:     internet explorer 8 on WIN7 at https://www.google.com/ &gt;, &lt;TestCase: internet explorer 8 on WIN7 at https://www.google.com/search?q=mooo &gt;, &lt;TestCase: internet explorer 8 on WIN7 at https://www.google.com/search?q=mooo &gt;, ...]
  &gt;&gt;&gt; TestCase.objects.count()
  454
  </code></pre>
  
  <p>Please feel free to ask for more details!</p>