1

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.

2
  • It's impossible to answer without access to your app's code and revision history. Is your model managed by the ORM or is it a legacy table ? When have this "competition_category" column be created and is there a matching migration ? (hint: read your app's migrations and check the django_migrations table to find out which ones have been applied and when). Commented Oct 19, 2017 at 11:07
  • There is something wrong with the migrations. Check your database see if the column competition_category actually exists. I would suggest you to rollback the migrations one by one and reapplying them to figure out where this issue happened. Commented Oct 19, 2017 at 11:08

1 Answer 1

3
  • 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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! Dropping the database was the only thing that worked this time :)
@user3257736 thats the last resort.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.