0

I have a below model,

class PersonIndustry(DFModel):
    person = models.ForeignKey(
        Person, models.DO_NOTHING, blank=True, null=True)
    industry = models.CharField(max_length=50, blank=True, null=True)

    class Meta:
        db_table = ‘person_industry'

My postgres database contains person_industry table.

When I registered this model in admin site it is giving me below error,

ProgrammingError at /admin/apis/personindustry/
relation "personindustry" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM “personindustry"

I am quite confuse why it is searching for personindustry instead of person_industry. Please advise.

2 Answers2

0

I also had this problem recently, what I did is:

# Clear migrations history
python manage.py migrate --fake APP_NAME zero

Then, delete the migrations files and .pyc files except for init.py. Now, make migrations:

python manage.py makemigrations APP_NAME

Now, fake the intial migrate. That will fake the intial table with name personindustry:

python manage.py migrate --fake-initial

*Note:- Feel free to ask. Refs

Biplove Lamichhane
  • 3,995
  • 4
  • 14
  • 30
  • My tables has lot of data in it. I don’t want to miss those. Does this method with impact the data? –  Jul 07 '20 at 03:08
  • I don't think that will effect the data, but I am not sure. Better make backup data. [See](https://stackoverflow.com/questions/3682866/how-to-create-a-backup-of-a-single-table-in-a-postgres-database) – Biplove Lamichhane Jul 07 '20 at 03:14
0

My meta class was creating problem,

class DFModel(models.Model, metaclass=DFModelBase):

    class Meta:
        abstract = True

I changed it to default,

class PersonIndustry(models.Model):
    person = models.ForeignKey(
        Person, models.DO_NOTHING, blank=True, null=True)
    industry = models.CharField(max_length=50, blank=True, null=True)

    class Meta:
        db_table = ‘person_industry'

It is loading now.