操作错误Django管理员
我正在django上使用一个遗留的mysql数据库。我需要在“bibliografias”管理页面上显示另一个表,它被db用外键引用。 我得到这个错误: 操作错误位于/admin/accounts/bibrest51/(1054,“未知列 “字段列表”中的“bibrest51.tema_f_id”) 管理员操作错误Django管理员,django,Django,我正在django上使用一个遗留的mysql数据库。我需要在“bibliografias”管理页面上显示另一个表,它被db用外键引用。 我得到这个错误: 操作错误位于/admin/accounts/bibrest51/(1054,“未知列 “字段列表”中的“bibrest51.tema_f_id”) 管理员 def get_tema(self, obj): return obj.tema_f.tema_nome get_tema.short_description =
def get_tema(self, obj):
return obj.tema_f.tema_nome
get_tema.short_description = 'Tema'
models.py
class Tema(models.Model):
tema_id = models.AutoField(primary_key=True)
tema_nome = models.CharField(max_length=150, blank=True, null=True)
datacriado = models.DateTimeField(db_column='dataCriado') # Field name made lowercase.
@property
def tema_id(self):
return self.tema_id
def __str__(self):
return str(self.tema_id)
class Meta:
managed = False
db_table = 'tema_table'
class Bibrest51(models.Model):
cadastro_id = models.AutoField(primary_key=True)
tema_f = models.ForeignKey(Tema,on_delete=models.CASCADE)
tema_id = models.IntegerField(blank=True, null=True)
class Meta:
managed = False
db_table = 'bibrest51'
verbose_name = "Bibliografia"
verbose_name_plural = "Bibliografias"
您需要通过运行migrate命令来创建auth表
python manage.py migrate感谢您的回答,问题在于ID命名,django不喜欢这样。