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 6158385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:56:53+00:00 2026-05-23T20:56:53+00:00

I have a field on a model that’s marked unique: uid = models.CharField(max_length=255, blank=False,

  • 0

I have a field on a model that’s marked unique:

uid = models.CharField(max_length=255, blank=False, null=False, unique=True)

I’m trying to use get() to get the one Profile that should match this uid:

UserProfile.objects.get(uid=fr_uid)

The problem is that this line raises a MultipleObjectsReturned exception for some users even though that field is marked unique:

Line: return self.get_query_set().get(*args, **kwargs)

Local variables:
clone   [<Profile: John Smith>, <Profile: John Smith>]
num     2

If I get the same profile from a shell, I only get one back:

Profile.objects.get(uid='abc1234')
<Profile: John Smith>

Now I understand that I should probably be handling a MultipleObjectsReturned exception anyway, but I cannot understand why I would ever get multiple objects returned on a field marked unique.

  • 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-05-23T20:56:54+00:00Added an answer on May 23, 2026 at 8:56 pm

    Have you made any modifications to the manager? Or are you doing any sort of filtering on the queryset before calling get() on it? In particular, using Q objects for OR boolean searches can often result in the same object being returned multiple times. If that’s the case, call distinct() on the queryset before get().

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

Sidebar

Related Questions

I have a model that has this field on it: token = models.CharField(max_length=32, default=,
from django.db import models class Entry(models.Model): title = models.CharField(max_length=30,null=False) body_text = models.TextField(max_length=255) author =
In my model I have a field: country = models.CharField(_('Country'), max_length=2, choices=COUNTRIES) Where COUNTRIES
Specifically, I have a model that has a field like this pub_date = models.DateField(date
I have a field in my Rails model that has max length 255. I'm
I have a Django model that contains a date field: class Event(models.Model): event_date =
I have a Model that looks like: class MyModel(Model): name = models.TextField(blank=True, default='') bio
I have model Article it has field title with some text that may contain
I have a Django form that uses an integer field to lookup a model
I have a model that contains one-to-one fields to other models. I over rid

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.