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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:12:25+00:00 2026-06-17T23:12:25+00:00

I have a django model: class ActivationCode(models.Model): id = models.FloatField(primary_key=True) user = models.ForeignKey(‘User’, to_field=’id’,

  • 0

I have a django model:

class ActivationCode(models.Model):
    id = models.FloatField(primary_key=True)
    user = models.ForeignKey('User', to_field='id', on_delete=models.CASCADE)

I was having a hard time selecting an ActivationCode instance, so I tried to get the instance using its own id:

activation_codes = ActivationCode.objects.all()
print len(tuple(activation_codes))
>>> 1
for code in activation_codes:
    cid = code.id
ActivationCode.objects.get(id=cid)
>>> DoesNotExist: ActivationCode matching query does not exist.

What’s going on? Why does it say the object doesn’t exist when I’m using its own id? How come I can get the instance using .all() but not .get()?

It might be worth noting that the above code is running in a class-based view in a test environment (TestCase). When I try the same thing in the terminal, it works fine.

  • 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-17T23:12:26+00:00Added an answer on June 17, 2026 at 11:12 pm

    Floats as primary keys are a Bad Idea.

    You cannot guarantee the float representation is exactly the same on all levels. Python float implementation is interpreter-specific and likely differs in precision from your DB doubles.

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

Sidebar

Related Questions

I have the the following Django model: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) full_name
I have this model in django: class JournalsGeneral(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField(Code,
I have a symmetrical many-to-many relationship in Django class Person(models.Model): id = models.CharField(max_length=32, primary_key=True)
I have a Django model: class Project(models.Model): user = models.ForeignKey(User) zipcode = models.CharField(max_length=5) module
I have a model.py: class usercommand(models.Model): user = models.ForeignKey(User, blank=False) a_field = models.PositiveIntegerField(null=True, blank=True)
I have a simple Django model like: class Person(models.Model): referrer = models.ForeignKey('self', null=True) ...
I have a Django model: class Note(models.Model) : text = models.TextField() owner = models.ForeignKey(User)
I have a basic Django model like: class Business(models.Model): name = models.CharField(max_length=200, unique=True) email
Let's say I have the following Django model: class Info(models.Model): instrument = models.ForeignKey('Instrument') date
I have a django model as following class Project(models.Model) name=models.CharField(max_length=200) class Application(models.Model) proj=models.ForeignKey(Project, null=True,

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.