Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango 1.3 Matching query does not exist
    primarykey
    data
    text
    <p>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.</p> <p>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:</p> <p>Claim_status</p> <pre><code> 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 </code></pre> <p>lk_claim_status</p> <pre><code> 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) </code></pre> <p>My models:</p> <pre><code>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' </code></pre> <p>-- end claim_status.py -- start lk_claim_status.py</p> <pre><code>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' </code></pre> <p>I have not used in any pages yet but have just tested them out with the manage.py shell</p> <p>Here have been my tests</p> <pre><code>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" </code></pre> <p>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.</p> <pre><code>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 </code></pre> <p>With the above test I get this:</p> <pre><code>&gt;&gt;&gt; for status in status_list: ... print status.claim_status.claim_status ... Traceback (most recent call last): File "&lt;console&gt;", line 2, in &lt;module&gt; 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. </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload