【问题标题】:RecursionError : maximum recursion depth exceeded while calling a Python objectRecursionError : 调用 Python 对象时超出最大递归深度
【发布时间】:2020-09-14 04:37:58
【问题描述】:

我在尝试打开模型时在管理控制台中遇到错误。如何解决它

模型.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) 

当我选择某个项目时 它显示此错误

【问题讨论】:

  • 为什么你的主键是自引用外键?那可能是你的问题
  • 感谢您的回答,如何解决这个问题?加入表? @伊恩谢尔文顿

标签: python django


【解决方案1】:

从模型中删除 id 字段,因为您已将其作为模型本身的外键引用。如果没有明确选择模型中的字段,则会自动生成 id 字段。

【讨论】:

    猜你喜欢
    • 2017-11-07
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-25
    • 2020-01-05
    • 1970-01-01
    • 2020-07-13
    相关资源
    最近更新 更多