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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:44:26+00:00 2026-05-27T14:44:26+00:00

I have a question about this error and hope someone has ran into it

  • 0

I have a question about this error and hope someone has ran into it like I have. I am getting this error on a model when trying to use the Models.ForeignKey field. I can verify that the table the foreign key is used in exists, as well as the table that the fk references exists. I can get the model to work if I use a CharField but that is no fun.

Here are the tables(using Postgresql 9.0) I did not design so please don’t rag on me too much if you do not like it, although I cannot guarantee I would have designed it any better:

Claim_status

     Column      |            Type             |                               Modifiers                                
-----------------+-----------------------------+------------------------------------------------------------------------
 claim_no        | character varying(30)       | not null
 claim_status    | character varying(15)       | 
 userid          | character varying(40)       | not null
 note            | character varying(255)      | 
 time            | timestamp without time zone | default now()
 claim_status_id | integer                     | not null default nextval('claim_status_claim_status_id_seq'::regclass)
Indexes:
    "claim_status_pkey" PRIMARY KEY, btree (claim_status_id)
    "ndx_claim_status_claim_no" btree (claim_no) CLUSTER
    "ndx_claim_status_claim_status" btree (claim_status)
    "ndx_claim_status_date_time" btree (date("time"))
    "ndx_claim_status_time" btree ("time")
    "ndx_claim_status_upper_userid" btree (upper(userid::text))
    "ndx_claim_status_userid" btree (userid)
Foreign-key constraints:
    "$1" FOREIGN KEY (claim_status) REFERENCES lk_claim_status(claim_status)
    "claim_status_claim_no_fkey" FOREIGN KEY (claim_no) REFERENCES claim(claim_no) ON UPDATE CASCADE

lk_claim_status

        Column        |         Type          |   Modifiers   
----------------------+-----------------------+---------------
 claim_status         | character varying(15) | not null
 description_internal | character varying(35) | not null
 description_web      | character varying(35) | not null
 display_insured_web  | boolean               | default false
 display_rep_web      | boolean               | default false
Indexes:
    "lk_claim_status_pkey" PRIMARY KEY, btree (claim_status)
Referenced by:
    TABLE "claim_status" CONSTRAINT "$1" FOREIGN KEY (claim_status) REFERENCES lk_claim_status(claim_status)

My models:

from django.db import models
from test.django.common.models.claim.lk_claim_status import LkClaimStatus

class ClaimStatus(models.Model):
    claim_no = models.CharField(max_length=40)
    # the foreign key does not work here, you get matching query error for some reason.
    claim_status = models.ForeignKey(LkClaimStatus, db_column='claim_status')
    #claim_status = models.CharField(max_length=15)
    userid = models.CharField(max_length=40)
    note = models.CharField(max_length=255)
    time = models.DateTimeField(auto_now=True)
    claim_status_id = models.AutoField(primary_key=True)
    class Meta:
        db_table = u'claim_status'

— end claim_status.py — start lk_claim_status.py

from django.db import models

class LkClaimStatus(models.Model):
    claim_status = models.CharField(max_length=15, primary_key=True)
    description_internal = models.CharField(max_length=35)
    description_web = models.CharField(max_length=35)
    display_insured_web = models.BooleanField()
    display_rep_web = models.BooleanField()
    class Meta:
        db_table = u'lk_claim_status'

I have not used in any pages yet but have just tested them out with the manage.py shell

Here have been my tests

from test.django.common.models.claim.claim_status import ClaimStatus
from test.django.common.models.claim.lk_claim_status import LkClaimStatus
status_list = ClaimStatus.objects.filter(claim_no='TEST')
for status in status_list:
  try:
    print status.claim_status.claim_status
  except LkClaimStatus.DoesNotExist:
    print "Got a blank one"

That last test prints out nothing but the except print statement. If I use the CharField option from the ClaimStatus model I can print a status.claim_status and get a value from the db table.

from test.django.common.models.claim.claim_status import ClaimStatus
from test.django.common.models.claim.lk_claim_status import LkClaimStatus
status_list = ClaimStatus.objects.filter(claim_no='TEST')
for status in status_list:
    print status.claim_status.claim_status

With the above test I get this:

>>> for status in status_list:
...     print status.claim_status.claim_status
... 
Traceback (most recent call last):
  File "<console>", line 2, in <module>
  File "/usr/lib/python2.5/site-packages/django/db/models/fields/related.py", line 315, in __get__
    rel_obj = QuerySet(self.field.rel.to).using(db).get(**params)
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 349, in get
    % self.model._meta.object_name)
DoesNotExist: LkClaimStatus matching query does not exist.

I would understand this if the table did not exist or the fields did not exist, but they do? I can verify as well that with the test there are no null values for that claim_status field in either table.

  • 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-27T14:44:26+00:00Added an answer on May 27, 2026 at 2:44 pm

    I can definitely see one problem with your models here. When you define a ForegnKey field with the name “claim_status”, Django will be automatically creating an attribute on your model instances called “claim_status_id” which will be used to store the raw value of the “claim_status” database column. However, you already have a primary key field with the same name, which probably leads to a conflict.

    I am not sure what is the official way of solving this problem, but you could try to subclass ForeignKey and override its get_attname() method to return something else.

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

Sidebar

Related Questions

I have a question about an error I'm getting when trying to compile a
I have already posted a question about this, but the situation has changed sufficiently
I have quick question about jQuery plugins, hope somebody out there has some advice.
I have a question about this question . I posted a reply there but
Hi I have a question about this pointer, when an object is constructed, when
I have seen this question about deploying to WebSphere using the WAS ant tasks.
I have a question about locking. This doesn't have to be only about record
I have a question about using new[] . Imagine this: Object.SomeProperty = new[] {string1,
I have little question about how web browser retrieve webpage? I know this User
This question about Timers for windows services got me thinking: Say I have (and

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.