Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django: migration x in app x has no Migration class

here is the exact error

django.db.migrations.loader.BadMigrationError: Migration 0001_initial in app django_comments has no Migration class

I have no idea what this means and I don't know where to go. I did some work with my venv, making a new one and then I was trying to get everything back to normal. Installing this and that...I lost track of everything I was doing because my laptop died which really pissed me off.

Any idea where to go from here?

EDIT:

If I try to upgrade django_comments I get the following error:

 Could not find a version that satisfies the requirement django-comments (from versions: 0.2a, 0.3.1a, 0.3.2a, 0.3.3a, 0.3a, 1.0.0.b, 1.0.0.b, 1.0.0.b)

Cleaning up... No distributions matching the version for django-comments Storing debug log for failure in /home/jeff/.pip/pip.log

like image 476
Joff Avatar asked Dec 11 '15 09:12

Joff


People also ask

Why Makemigrations is not working?

This may happen due to the following reasons: You did not add the app in INSTALLED_APPS list in settings.py (You have to add either the app name or the dotted path to the subclass of AppConfig in apps.py in the app folder, depending on the version of django you are using). Refer documentation: INSTALLED_APPS.

What is the difference between Makemigrations and migrate in Django?

migrate , which is responsible for applying and unapplying migrations. makemigrations , which is responsible for creating new migrations based on the changes you have made to your models.


3 Answers

I had this problem, and it turned out that I had accidentally copied a non-migration file into one of my migrations folders. Removing the errant file fixed this for me.

like image 77
AlexJerez Avatar answered Nov 10 '22 17:11

AlexJerez


As the problem is related to the migration, you have to understand first how it works, django check you database schema compares it with your model then generates the migration script. Every migration script is executed one time, because django keep tracking you migrations. This is managed by a table called django_migrations that is created in your database the first time migrations are ran. So I will suggest two things:

  1. if you have no data in your db, or no important data so I suggest to drop it and create new one then apply all the migrations again
  2. if you have important data, try to look in the django_migrations table and delete the row containing django_comments migrations and most probably the correspondent table, so you can apply the migration again
like image 39
Dhia Avatar answered Nov 10 '22 19:11

Dhia


You are probably using an old version of django-contrib-comments that only supports Django 1.6. It will have South migrations in the migrations/ folder, instead of the new Django migrations.

To fix this, simply upgrade django-contrib-comments:

pip install -U django-contrib-comments
like image 2
knbk Avatar answered Nov 10 '22 17:11

knbk