Opened 10 years ago

Closed 10 years ago

#23618 closed Cleanup/optimization (fixed)

Migrations only work for apps containing models

Reported by: David Seddon Owned by: nobody
Component: Migrations Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Migrations only work for apps containing a This means that if you create a data migration (./ makemigrations --empty <app>) for an app without a, it will fail to execute when running ./ migrate.

I think it would be better if apps containing migrations would run, regardless of having that empty file.

This is because it can be a nice structure to have a 'main' app responsible for general project-wide stuff, which includes running data migrations that aren't directly related to models. An example might be assigning some permissions in the database to a particular role, but for a third party app.

Not sure if this is the only place where the check is made, but django.db.migrations.loader.MigrationLoader.load_disk() uses the following test to see whether to include the app:

if app_config.models_module is None:

Change History (8)

comment:1 by Tim Graham, 10 years ago

See also #22645 - "GIS tests break without a`. We removed that check and then something else broke (I forget what) so it had to be reverted.

comment:2 by Claude Paroz, 10 years ago

Typical GIS error (whatever the backend) when removing the app_config.models_module check:

Applying gis_migrations.0001_initial...Traceback (most recent call last):
  File "./", line 391, in <module>
    options.failfast, options.modules)
  File "./", line 234, in django_tests
    test_labels or get_installed(), extra_tests=extra_tests)
  File "/home/jenkins/workspace/django-pull-requests/database/mysql_gis/python/python2.7/django/test/", line 151, in run_tests
    old_config = self.setup_databases()
  File "/home/jenkins/workspace/django-pull-requests/database/mysql_gis/python/python2.7/django/test/", line 113, in setup_databases
    return setup_databases(self.verbosity, self.interactive, self.keepdb, **kwargs)
  File "/home/jenkins/workspace/django-pull-requests/database/mysql_gis/python/python2.7/django/test/", line 304, in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
  File "/home/jenkins/workspace/django-pull-requests/database/mysql_gis/python/python2.7/django/db/backends/", line 385, in create_test_db
  File "/home/jenkins/workspace/django-pull-requests/database/mysql_gis/python/python2.7/django/core/management/", line 118, in call_command
    return command.execute(*args, **defaults)
  File "/home/jenkins/workspace/django-pull-requests/database/mysql_gis/python/python2.7/django/core/management/", line 419, in execute
    output = self.handle(*args, **options)
  File "/home/jenkins/workspace/django-pull-requests/database/mysql_gis/python/python2.7/django/core/management/commands/", line 193, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/home/jenkins/workspace/django-pull-requests/database/mysql_gis/python/python2.7/django/db/migrations/", line 63, in migrate
    self.apply_migration(migration, fake=fake)
  File "/home/jenkins/workspace/django-pull-requests/database/mysql_gis/python/python2.7/django/db/migrations/", line 91, in apply_migration
    if self.detect_soft_applied(migration):
  File "/home/jenkins/workspace/django-pull-requests/database/mysql_gis/python/python2.7/django/db/migrations/", line 135, in detect_soft_applied
    apps = project_state.render()
  File "/home/jenkins/workspace/django-pull-requests/database/mysql_gis/python/python2.7/django/db/migrations/", line 89, in render
ValueError: Lookup failed for model referenced by field gis_migrations.Household.neighborhood: gis.Neighborhood

comment:3 by Claude Paroz, 10 years ago

I've update
At least the test suite now starts, but strangely, the test suite passes when I only run it with django.contrib.gis test label, but fails with no test labels.

comment:4 by Tim Graham, 10 years ago

Has patch: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

comment:5 by Claude Paroz, 10 years ago

Needs documentation: set
Patch needs improvement: unset

I think I resolved the test-order-related failures.
I guess this warrants a release note.

comment:6 by Claude Paroz, 10 years ago

Needs documentation: unset
Version: 1.7master

comment:7 by Tim Graham, 10 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Claude Paroz <claude@…>, 10 years ago

Resolution: fixed
Status: newclosed

In e50e0ee27bf16090fe36a87cf91fe2baa27b70f1:

Fixed #23618 -- Allowed apps with no models to still have migrations

Basically a4737bf6ae reapplied.

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