Nora
Nora

Reputation: 1893

ProgrammingError in Django when adding a new model-instance to the Database, what could be wrong?

When using the Django Admin panel, I am able to add new instances to Users and Groups. The same thing goes for all my apps, except for one. This one app, resultregistration, always gives me a ProgrammingError whenever I try to add a new model. For example, this app has a Competition-model where data about a sport competition should be stored.

When I click "+ Add" I am taken to the correct site where I can add a new competition. However, when I press save I get:

ProgrammingError at /admin/resultregistration/competition/add/

column "competition_category" of relation "resultregistration_competition" does not exist LINE 1: INSERT INTO "resultregistration_competition" ("competition_c...

Of course, I assume something is wrong with the migrations. However, I have run python manage.py makemigrations appname, and python manage.py migrate appname, and that works fine. I get a message that there are "No changes detected", and "No migrations to apply".

I have tried solutions posted on SO, but none of them worked.

What is the general reason for this error? And does anyone know what could be wrong in this specific case? Could one get this error if something is wrongly defined in the model? Or does it have to be a migration problem?

Thank you so much! Any help would be truly appreciated. Also, I am using PostgreSQL, if that helps.

Upvotes: 1

Views: 934

Answers (1)

Shikhar Thapliyal
Shikhar Thapliyal

Reputation: 610

  • Make sure you have _ init _.py file under the migrations folder for that paticular app.
  • Running manage.py makemigrations always makes a migration file if there are any changes in your models.py

If nothing works and there isnt much data present in your database, end resolution is to delete all migrations files (if any) for that app or for the project, in terminal type "sudo -su postgres" then type "psql".

Drop your database and create a new one. Run manage.py makemigrations to check if migration file has been created or not. Then migrate with manage.py migrate

Upvotes: 3

Related Questions