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

  • SEARCH
  • Home
  • 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 8897761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:25:52+00:00 2026-06-15T00:25:52+00:00

Racking my brain on this one. The model seems true, theoretically all of the

  • 0

Racking my brain on this one. The model seems true, theoretically all of the commented permutations should work— but the only things that can successfully retrieve the user is .filter and .all; .get doesnt work; I can deal with using either .filter or .all —- but why isn’t get working?

I’ll reiterate that a direct SQL query works 100% in this case. All imports are in place and things are functioning great at a low level — again, Filter works, All works, but get fails for some reason.

class UserModelTest(TestCase):
def test_getUserByUsername(self):
    sanity = True
    try:
        #u = User.objects.filter(username='wadewilliams')
        u = User.objects.get(username='wadewilliams')
        #u = User.objects.get(pk=15773)
        #u = User.objects.all()
    print u
    except User.DoesNotExist:
        sanity = False

    self.assertEqual(sanity, True)

… That test fails unless I uncomment either filter or all… both gets, no go.

And the model…

class User(models.Model):
    userid = models.IntegerField(primary_key=True, db_column='userID')
    username = models.CharField(max_length=135)
    realname = models.CharField(max_length=150, db_column='name')
    email = models.CharField(max_length=765, blank=True)

class Meta:
    db_table = u'users'

def __unicode__(self):
    return self.username + ' (' + self.email + ')'
  • 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-15T00:25:54+00:00Added an answer on June 15, 2026 at 12:25 am

    The test suite creates a mock database that is blank, so no users can be found even though the exist in the production/development database.

    From the docs:
    Finding data from your production database when running tests?
    If your code attempts to access the database when its modules are compiled, this will occur before the test database is set up, with potentially unexpected results. For example, if you have a database query in module-level code and a real database exists, production data could pollute your tests. It is a bad idea to have such import-time database queries in your code anyway – rewrite your code so that it doesn’t do this.

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

Sidebar

Related Questions

I've been racking my brain on this one, searching all over the place and
Happy thanksgiving all: I've been racking my brain around this one for a half
This is really racking my brain, but maybe I'm trying to hard. I'm passing
Ok, I've been racking my brain on this one solo for too long. I've
I've been racking my brain trying to figure this one out as it's been
I've been racking my brain trying to get this to work. My event for
I've been racking my brain about how to do this in one query without
I have been racking my brain over this all day today. I have the
I have been racking my brain all morning with this. I am using Eclipse
I've been racking my brain with this one. I have two arrays: Array 1

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.