0

I am getting an error in admin console while trying to open a model . How to fix it

Model.py

class TbSysEmailconfig(models.Model):
    id = models.ForeignKey('self', models.DO_NOTHING, db_column='Id', primary_key=True)  # Field name made lowercase.
    emailtemplateid = models.ForeignKey(TbMasEmailtemplate, models.DO_NOTHING, db_column='EmailTemplateId')
    emailfromname = models.CharField(db_column='EmailFromName', max_length=100, blank=True, null=True)
    emailfrom = models.CharField(db_column='EmailFrom', max_length=100)
    credential = models.CharField(db_column='Credential', max_length=100)
    password = models.CharField(db_column='Password', max_length=100)
    post = models.IntegerField(db_column='Post', blank=True, null=True)
    host = models.CharField(db_column='Host', max_length=100)
    priority = models.CharField(db_column='Priority', max_length=100, blank=True, null=True)
    maximumday = models.IntegerField(db_column='MaximumDay', blank=True, null=True)
    maximumminute = models.IntegerField(db_column='MaximumMinute', blank=True, null=True)
    systemid = models.IntegerField(db_column='SystemId')
    partfiletemplate = models.CharField(db_column='PartFileTemplate', max_length=500, blank=True, null=True)
    comment = models.CharField(db_column='Comment', max_length=1000, blank=True, null=True)
    ismaildefault = models.SmallIntegerField(db_column='IsMailDefault')
    maildefault = models.CharField(db_column='MailDefault', max_length=4000, blank=True, null=True)
    createddate = models.DateTimeField(db_column='CreatedDate')
    createdbyuserid = models.IntegerField(db_column='CreatedByUserId')
    updateddate = models.DateTimeField(db_column='UpdatedDate')
    updatedbyuserid = models.IntegerField(db_column='UpdatedByUserId')
    delflag = models.SmallIntegerField(db_column='DelFlag')

    class Meta:
        db_table = 'TB_SYS_EmailConfig'

admin.py

from django.contrib import admin
from .model import TbSysEmailconfig 
#Modifire 
admin.site.register(TbSysEmailconfig) 

enter image description here

When I select some item it show this error

enter image description here

2
  • 3
    Why is your primary key a self-referential foreign key? That would probably be your issue Commented Sep 14, 2020 at 4:40
  • thank for answer , how to fix this issue ? join table ? @Iain Shelvington Commented Sep 14, 2020 at 4:46

1 Answer 1

1

Remove the id field from your model, as you have referenced it as a foreign key to the model itself. The id field is automatically generated if no field in the model is explicitly chosen.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.