Home > other >  Django App Issue with ColumnName changed to lower case in the postgres DB
Django App Issue with ColumnName changed to lower case in the postgres DB

Time:12-31

I have a working Django app with Postgres DB in the backend. However the coulmn names are updated and switched to lowercase name in backend database, for eg:

Earlier columnName was AccountName, now changed to accountname all lowercase. This cases the app to break since the model refers to the oldName.

I tried changing to the Model to the lowercase name but it breaks at different places like DataFrame name and have to make lot of changes to make it work.

class AccountStatus(models.Model):
    AccountNumber = models.CharField(max_length=255, null=True)
    AccountName = models.CharField(max_length=255, null=True)

is there any simple solution to this issue, maybe using some alias or any parameter to pass etc?

Thanks for the help.

Tried this :

class AccountStatus(models.Model):
    accountnumber = models.CharField(max_length=255, null=True)
    accountname = models.CharField(max_length=255, null=True)

This results in cascade of changes in Filters, DataFrame key names etc and many other places.

I am trying to figure out an easy solution for this?

CodePudding user response:

You can specify a db_column=… parameter [Django-doc] to specify the name of the column at the database side:

class AccountStatus(models.Model):
    AccountNumber = models.CharField(
        max_length=255, db_column='accountnumber', null=True
    )
    AccountName = models.CharField(
        max_length=255, db_column='accountname', null=True
    )
  • Related