[Answered ]-Converting IntegerField to ForeignKey from recovered database in Django

1👍

You can specify that the name of the database column is otec with db_column='otec':

class ChileStudents(models.Model):
    otec = models.ForeignKey(db_column='otec', blank=True, null=True)
    # More stuff goes here
    updated_at = models.DateTimeField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'chile_students'

But since the table already exists, you can not make it managed = True, since then Django will try to create the table at the database side, create/remove columns, etc. Since here the table already exists, you can not let Django handle that, since then it will aim to create a table that already exists.

Leave a comment