0
votes

I'm using a legacy mysql database on django. I need to display another table on the "bibliografias" admin page, it is referenced by the db with foreign keys. I get this error:

OperationalError at /admin/accounts/bibrest51/ (1054, "Unknown column 'bibrest51.tema_f_id' in 'field list'")

admin.py

 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"
1

1 Answers

1
votes

you need to create auth table by running migrate command

python manage.py migrate