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 |
Description
Migrations only work for apps containing a models.py
. This means that if you create a data migration (./manage.py makemigrations --empty <app>
) for an app without a models.py
, it will fail to execute when running ./manage.py 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: continue
Change History (8)
comment:1 by , 10 years ago
comment:2 by , 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 "./runtests.py", line 391, in <module> options.failfast, options.modules) File "./runtests.py", 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/runner.py", 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/runner.py", 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/runner.py", 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/creation.py", line 385, in create_test_db test_flush=True, File "/home/jenkins/workspace/django-pull-requests/database/mysql_gis/python/python2.7/django/core/management/__init__.py", 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/base.py", 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/migrate.py", 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/executor.py", 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/executor.py", 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/executor.py", 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/state.py", line 89, in render model=lookup_model, ValueError: Lookup failed for model referenced by field gis_migrations.Household.neighborhood: gis.Neighborhood
comment:3 by , 10 years ago
I've update https://github.com/django/django/pull/3340.
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 , 10 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
comment:5 by , 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 , 10 years ago
Needs documentation: | unset |
---|---|
Version: | 1.7 → master |
comment:7 by , 10 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:8 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
See also #22645 - "GIS tests break without a models.py`. We removed that check and then something else broke (I forget what) so it had to be reverted.