Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8321031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:52:36+00:00 2026-06-08T22:52:36+00:00

I have a django application with a model named TestCase . There are 9

  • 0

I have a django application with a model named TestCase. There are 9 instances of the model currently stored in the DB, which I can see by running TestCase.objects.all() in the shell, and they’re also being displayed correctly in my views.

However, in a management command I’m running, the same query (TestCase.objects.all()) 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.

Any ideas on what could be causing this?

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 TestCase.objects.all().aggregate(Max('test_run'))).

I’m using Django 1.4.

This is the management command:

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):
    ...

the output is ALL: []. I’ve omitted the source of the traverse() method, but the problem is visible before that, so it shouldn’t impact anything.

Here’s the output from the shell showing the instances in the DB:

[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)
>>> from mainapp.models import TestCase
>>> TestCase.objects.all()
[<TestCase: internet explorer 8 on WIN7 at https://www.google.com/ >, <TestCase:     internet explorer 8 on WIN7 at https://www.google.com/ >, <TestCase: internet explorer 8 on WIN7 at https://www.google.com/search?q=mooo >, <TestCase: internet explorer 8 on WIN7 at https://www.google.com/search?q=mooo >, ...]
>>> TestCase.objects.count()
454

Please feel free to ask for more details!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:52:37+00:00Added an answer on June 8, 2026 at 10:52 pm

    The following line of your Command is resetting the database and clearing data:

    management.call_command('reset', 'mainapp', interactive=False) 
    

    If you remove this line, the record count in the shell and command will be equivalent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following models setup in my Django application class School(models.Model): name = models.TextField()
I have a django application using multiple databases. Given an instance of a model,
I have two models in my Django 1.1.1 application: class UserRequest(models.Model): # blah blah
HI I have a django application running on app engine and I want to
My application uses Django non-rel . I don't have access to model. I have
In my application I have an extended User model called UserProfile. This user can
I'm currently doing a firewall management application for Django, here's the (simplified) model :
I have Django application with inline in place: class Account(models.Model): ContractNum = models.PositiveIntegerField(unique=True, blank=True,
I am implementing an application with django, which has a model with a FileField:
I am using the standard User model (django.contrib.auth) which comes with Django. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.