0

I am developing a large django-based project. On my laptop I use SQLite3 as a database. I have created a lot of migrations for my models. Everything seems working.

Then I want to use PostgreSQL on the production server. I have prepared an empty database and trying to do manage.py syncdb. And suddenly I get an error due to not existing relation.

Operations to perform:
  Synchronize unmigrated apps: suit, messages, humanize, imagekit, staticfiles, crispy_forms, storages, django_extensions, localflavor, registration
  Apply all migrations: [here list of my apps], sites, user_auth, sessions, auth
Synchronizing apps without migrations:
  Creating tables...
    Creating table registration_registrationprofile
    Running deferred SQL...
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "user_auth_account" does not exist

Trying to drop my sqlite database and perform syncdb with the new sqlite: it creates the schema without issues.

Here I've realized that SQLite does not use Foreign Key relations and simply uses integer types for all references. So it works for sqlite. Very smart, Django. But all my models are depending of each other. And I want to use different databases.

Now I have a bunch of migrations working on SQLite only.

I understand that it is possible to run migrations one-by-one for each application where the model first gets created. But it would be a hell.

Is it possible to detect dependencies and run these migrations in correct order?

1 Answer 1

1

Django handles dependencies between models in migrations correctly. What it can't handle, and what it explicitly warns against in the docs, is unmigrated apps with dependencies on migrated apps:

Be aware, however, that unmigrated apps cannot depend on migrated apps, by the very nature of not having migrations. This means that it is not generally possible to have an unmigrated app have a ForeignKey or ManyToManyField to a migrated app; some cases may work, but it will eventually fail.

Warning

Even if things appear to work with unmigrated apps depending on migrated apps, Django may not generate all the necessary foreign key constraints!

In this specific case is seems that the registration app has a dependency on the user model. You need to upgrade this app to a version that has the necessary migration files to support Django 1.7+.

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

1 Comment

Awesome, thanks, buddy! In my case it was django-registration-redux==1.1. Updated it to 1.2 and everything works now!

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.