shahidpharm
shahidpharm

Reputation: 25

operationalError at admin/... at most 64 tables in a join

operationalError at /admin... at most 64 tables in a join

class ReagentInventory(models.Model):
    company = models.ForeignKey(Company, on_delete=models.CASCADE)
    manufacturing_unit = models.ForeignKey(ManufacturingUnit, on_delete=models.CASCADE)
    ManufacturingPlant = models.ForeignKey(ManufacturingPlant, on_delete=models.CASCADE)
    reagent_name = models.ForeignKey(Reagent, on_delete=models.CASCADE)
    storage_location = models.ForeignKey(StorageLocation, on_delete=models.CASCADE)
    current_stock = models.DecimalField(decimal_places=3, max_digits=10, )
    measuring_unit = models.ForeignKey(MeasurementUnit, on_delete=models.CASCADE)
    reagent_lot_no = models.CharField(max_length=20)
    reagent_mother_lot_no = models.CharField(max_length=20)
    challan_no = models.CharField(max_length=20)
    mother_expiry_date = models.DateField()
    assigned_expiry_date = models.DateField()
    received_date = models.DateField()
    opening_date = models.DateField(blank=True)
    number_of_container = models.IntegerField()
    packing_mode = models.ForeignKey(PackingMode, on_delete=models.CASCADE)
    manufacturing_country = models.ForeignKey(Country, on_delete=models.CASCADE)
    supplier = models.ForeignKey(Supplier, on_delete=models.CASCADE)
    manufacturer = models.ForeignKey(Manufacturer, on_delete=models.CASCADE)

class Meta:
    verbose_name_plural = 'Reagent Inventories'

def __str__(self):
    return self.reagent_name

def __unicode__(self):
    return self.reagent_name

Upvotes: -2

Views: 158

Answers (1)

Azhar Uddin Sheikh
Azhar Uddin Sheikh

Reputation: 684

Same Issue:

@admin.register(AcademicFee)
class AcademicFeeAdmin(admin.ModelAdmin):
    model = AcademicFee
    list_display = ('academic', 'name', 'fee', 'created_by', 'updated_by')
    search_fields = ('academic__name', 'name', 'created_by')
    readonly_fields = ('created_by', 'created_date', 'updated_by', 'updated_date')

created_by and updated_by are foreign keys to the User table. Adding list_select_related on AcademicFeeAdmin resolves this:

@admin.register(AcademicFee)
class AcademicFeeAdmin(admin.ModelAdmin):
    model = AcademicFee
    list_display = ('academic', 'name', 'fee', 'created_by', 'updated_by')
    search_fields = ('academic__name', 'name', 'created_by')
    readonly_fields = ('created_by', 'created_date', 'updated_by', 'updated_date')
    #added below line
    list_select_related = ('created_by', 'updated_by')

In your case you need to use select_related on fields which are foreign keys. Also look into this post.

Upvotes: 0

Related Questions