0

I have been working on a Django (version 1.7.6) project for various months. Throughout this time each application evolved a good deal and there now various dozens of migrations.

I would like to deploy this project into a new development environment. I set up a database with an empty schema and updated settings.py accordingly. Now I would like to recreate the database structure from the migrations, however I get the following exception when I run python manage.py migrate:

File "/usr/lib/python2.7/dist-packages/django/db/backends/utils.py", line 65, in execute return self.cursor.execute(sql, params) django.db.utils.ProgrammingError: table "modules_server_proj_locations" does not exist

modules_server_proj_locations refers to a many-to-many relationship that no longer exists, but for some reason the migrations are still trying use it.

I then tried to migrate with the --fake option, but this only results in a different exception:

File "/usr/lib/python2.7/dist-packages/django/contrib/contenttypes/models.py", line 58, in get_for_model " is migrated before trying to migrate apps individually." RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.

How should I proceed?

Luís de Sousa
  • 5,765
  • 11
  • 49
  • 86

1 Answers1

1

If this is your first release then you can drop the whole database, remove all the migration files and then run python manage.py makemigrations for a clean database and migration theme. Otherwise, probably you have to edit migration files and remove the table trace from all.

Danial Tz
  • 1,884
  • 1
  • 15
  • 20
  • This is a sort of brute force solution. I can actually do it this way because the project is not yet in production; what if it was? And would you know what exactly is causing these exceptions? – Luís de Sousa Aug 06 '15 at 09:17
  • I know, one that I just did one hour ago for a project. It is a compromise of many hours to fix it or just get it done. The reason this happens is that usually you have a dependance on a 3rd party addon on the way, e.g. taggit, and at that time you had it installed. So, your app has a manytomany to taggit, but today you don't have taggit anymore, but your migration is still linking it, in my particular case. – Danial Tz Aug 06 '15 at 09:41
  • the question is a bit old, but as I found in the same need. After have simply created same user in the new DB(MySQL) I runned python manage.py migrate and I had all the table and structure as from the other system. Or course this without data, that indeed I will migrate in a second step. This prevent to avoid to delete migration files and have problem with dependencies – Carmine Tambascia May 31 '18 at 13:58