Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#25698 closed Uncategorized (invalid)

App without migrations depending on app with migrations fails on initial migrate call (postgres)

Reported by: Lucas Moeskops Owned by: nobody
Component: Migrations Version: 1.8
Severity: Normal Keywords: migrate postgres
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Lucas Moeskops)

Simple test example:
In a new project add 'django.contrib.sites' and your main app to the INSTALLED APPS setting.
Use postgres as database.
Make a model in your main app that uses a relation to django.contrib.sites:

from django.contrib.sites.models import Site
class MyModel(models.Model):
  my_site = models.ForeignKey(Site)

Migrate the project:

python manage.py migrate

It will fail to migrate with the message: django.db.utils.ProgrammingError: relation "django_site" does not exist. This is because it tries to migrate the apps without migrations before the apps with migrations.

To solve the problem, the app should have at least one migration. But maybe this needs to be documented. I couldn't find it in the documentation.

Change History (5)

comment:1 Changed 4 years ago by Lucas Moeskops

Description: modified (diff)

comment:2 Changed 4 years ago by Lucas Moeskops

Description: modified (diff)

comment:3 Changed 4 years ago by Simon Charette

Resolution: invalid
Status: newclosed

This is a documented limitation.

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.

comment:4 Changed 4 years ago by Lucas Moeskops

It is correct behaviour indeed, only the error message could be improved.

Last edited 4 years ago by Lucas Moeskops (previous) (diff)

comment:5 Changed 4 years ago by Tim Graham

I think improving the error message (about missing migrations) is tracked in #24484.

Note: See TracTickets for help on using tickets.
Back to Top