« Return to Thread: [Django] #11437: [soc2009/multidb] M2M Relationship with through=[model] whose primary key is renamed fails with wrong column name

Re: [Django] #11437: [soc2009/multidb] M2M Relationship with through=[model] whose primary key is renamed fails with wrong column name

by Django-3 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View in Thread

#11437: [soc2009/multidb] M2M Relationship with through=[model] whose primary key
is renamed fails with wrong column name
---------------------------------------------------+------------------------
          Reporter:  anonymous                     |         Owner:  nobody                      
            Status:  closed                        |     Milestone:                              
         Component:  Database layer (models, ORM)  |       Version:  soc2009/multidb            
        Resolution:  invalid                       |      Keywords:  multidb manytomany db_column
             Stage:  Unreviewed                    |     Has_patch:  0                          
        Needs_docs:  0                             |   Needs_tests:  0                          
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Changes (by anonymous):

  * status:  new => closed
  * resolution:  => invalid

Comment:

 I'm sorry, was my fault. I didn't run manage.py validate, which helpfully
 let me know:
 {{{
 Error: One or more models did not validate:
 adsales.adsalesadorderlistingbridge: "id": You can't use "id" as a field
 name, because each model au
 tomatically gets an "id" field if none of the fields have
 primary_key=True. You need to either remov
 e/rename your "id" field or add primary_key=True to a field.
 }}}

 I had declared my model like this:
 {{{
 class AdSalesAdOrderListingBridge(models.Model):
     id = models.IntegerField(db_column='ad_order_listing_bridgeId')
 }}}

 And just forgot to add the keyword argument primary_key=True.

 I can only assume that django would parse my model, not find a pk, and
 then overwrite my id field definition with the automatic id field (which
 of course wouldn't have db_column set, but would have primary_key set)

 Thanks for looking at this, even though it was my fault :(

 Perhaps a startup run-time model parsing exception (ImproperlyConfigured)
 should be generated if django is about to overwrite a field?

--
Ticket URL: <http://code.djangoproject.com/ticket/11437#comment:4>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django updates" group.
To post to this group, send email to django-updates@...
To unsubscribe from this group, send email to django-updates+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

 « Return to Thread: [Django] #11437: [soc2009/multidb] M2M Relationship with through=[model] whose primary key is renamed fails with wrong column name