16

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

Dhia
  • 10,119
  • 11
  • 58
  • 69
Joff
  • 11,247
  • 16
  • 60
  • 103
  • how many migrations do you have in your migrations folder? – utkbansal Dec 11 '15 at 09:11
  • in which one, I have many apps there and to be honest I don't know where the django_comments migrations would be – Joff Dec 11 '15 at 09:20
  • The app named django_comments – utkbansal Dec 11 '15 at 09:20
  • theres two in there, I didn't realize those were still called apps even though they werent in my project directory, should I delete them? – Joff Dec 11 '15 at 09:42
  • So you have 0001_initial and 0002_something? Or did you count `__init__` as well? – utkbansal Dec 11 '15 at 09:44
  • Which django version are you using? And it seems like django_commets is a third-party package and not your own app, is it ? – Dhia Dec 11 '15 at 09:54
  • @utkbansal, yes __init__ is in there as well – Joff Dec 12 '15 at 01:21
  • @DhiaTN yes django_comments is a package – Joff Dec 12 '15 at 01:21
  • The correct answer is knbk. The accepted answer DhiaTN contains useful information, butt not related to this error message at all. The exception BadMigrationError: "Migration *** in app *** has no Migration class" is raised if the "migrations/" directory in the aforesaid app contains a file ....py that is not a valid migration file. – hynekcer Oct 16 '17 at 07:36

8 Answers8

27

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.

AlexJerez
  • 480
  • 4
  • 5
4

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
Dhia
  • 10,119
  • 11
  • 58
  • 69
2

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
knbk
  • 52,111
  • 9
  • 124
  • 122
0

For me the migration file in question was empty. Deleting it solved my problem

7guyo
  • 3,047
  • 1
  • 30
  • 31
0

I had a file in the migration folder that didn't belong there. By deleting the misplaced file, I fixed the issue.

0
  • find the root directory of python in C: drive then delete python and also delete pip.
  • after deleting these both items download the new python and install it again.
yahya
  • 129
  • 1
  • 6
0

I've shared my Django ORM DB model between my custom APP and a Django App via symbolic links: ln -s

Simon Crane
  • 2,122
  • 2
  • 10
  • 21
0

For me I accidentally put other file(views.py) in migrations directory that cause this error.

Migration X in app X has no Migration class

This mean migrations loader search for class Migration in each py file in migrations directory in case of if migrations class not found then it'll raise this error

Kaushal
  • 666
  • 6
  • 15