Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In my specific case, I traced this bug down to declarations of ModelAdmin inline in my models.py code causing my model classes to be instantiated incorrectly, with broken <code>on_delete</code> behaviour the most visible side-effect of this. From my commit message:</p> <blockquote> <p>Fixed issue with cascading deletes not being done properly in Django DB.</p> <p>Turns out it's really important to not declare your ModelAdmins at the global scope in models.py, otherwise all the relationships between the different models get calculated before all the models are loaded and lots of them get left out. Really isn't that emphatic about this in the Django documentation.</p> </blockquote> <p>So in my original (broken) code, I would have the ModelAdmin for each Model declared immediately after it, a la:</p> <pre><code>class AccessPeriod( models.Model ): .... class AccessPeriodAdmin( models.ModelAdmin ): .... # This causes the metaclass setup for AccessPeriod to happen right now, # and since related models for AccessPeriod are not all declared yet, # relationship handling behaviour becomes broken for AccessPeriod admin.site.register( AccessPeriod, AccessPeriodAdmin ) class Payment( models.Model ): .... class PaymentAdmin( models.ModelAdmin ): .... # Same effect on the Payment model here admin.site.register( Payment, PaymentAdmin ) </code></pre> <p>The solution was to move all the ModelAdmin declarations out of <code>myapp/models.py</code> and into <code>myapp/admin.py</code> so that all the metaclass setup for each class happens after all the model declarations have been handled, and then all the relationships started behaving properly again.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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