#35711 closed Bug (invalid)
Running migrate with disabled migrations fails with version 5.1
Reported by: | Mounir | Owned by: | |
---|---|---|---|
Component: | Migrations | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
For some tests I run the migrate with the --run-syncdb
Since the update to 5.1 (from 5.0) I get this error:
Operations to perform: Apply all migrations: (none) Running migrations: No migrations to apply. Traceback (most recent call last): File "/app/./manage.py", line 30, in <module> main() File "/app/./manage.py", line 26, in main execute_from_command_line(sys.argv) File "/home/app/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line utility.execute() File "/home/app/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/app/venv/lib/python3.12/site-packages/django/core/management/base.py", line 413, in run_from_argv self.execute(*args, **cmd_options) File "/home/app/venv/lib/python3.12/site-packages/django/core/management/base.py", line 459, in execute output = self.handle(*args, **options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/core/management/commands/migrate.py", line 21, in handle super().handle(*args, **options) File "/home/app/venv/lib/python3.12/site-packages/django/core/management/base.py", line 107, in wrapper res = handle_func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/app/venv/lib/python3.12/site-packages/django/core/management/commands/migrate.py", line 336, in handle changes = autodetector.changes(graph=executor.loader.graph) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/app/venv/lib/python3.12/site-packages/django/db/migrations/autodetector.py", line 67, in changes changes = self._detect_changes(convert_apps, graph) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/app/venv/lib/python3.12/site-packages/pgtrigger/migrations.py", line 156, in _detect_changes return super()._detect_changes(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/app/venv/lib/python3.12/site-packages/django/db/migrations/autodetector.py", line 224, in _detect_changes self._sort_migrations() File "/home/app/venv/lib/python3.12/site-packages/django/db/migrations/autodetector.py", line 426, in _sort_migrations dep = self._resolve_dependency(dep)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/app/venv/lib/python3.12/site-packages/django/db/migrations/autodetector.py", line 279, in _resolve_dependency if dependency.app_label != "__setting__": ^^^^^^^^^^^^^^^^^^^^ AttributeError: 'tuple' object has no attribute 'app_label'
The disabling of migrations is done with the help of migration modules setting:
class DisableMigrations: def __contains__(self, item): return True def __getitem__(self, item): return None MIGRATION_MODULES = DisableMigrations()
Possible regression from https://github.com/django/django/commit/7dd3e694db17bc34f9ce73e516f853ebd16e19e7
Change History (7)
comment:1 by , 4 months ago
Description: | modified (diff) |
---|
comment:2 by , 4 months ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:3 by , 4 months ago
Based from Django's docs:
When you supply None as a value for an app, Django will consider the app as an app without migrations regardless of an existing migrations submodule. This can be used, for example, in a test settings file to skip migrations while testing (tables will still be created for the apps’ models). To disable migrations for all apps during tests, you can set the MIGRATE to False instead. If MIGRATION_MODULES is used in your general project settings, remember to use the migrate --run-syncdb option if you want to create tables for the app.
So, when I tried to set MIGRATION_MODULES for each app to None (without the DisableMigrations
pattern) I still get the same error.
Background: I used this approach before running some e2e tests, which run Django in a normal mode, disabling migrations helps speeding up the process.
comment:4 by , 4 months ago
I created a new project using 5.1, assigned None
to each entry in MIGRATION_MODULES
, and ran migrate --run-syncdb
without any issues.
You might have to provide a project that reproduces I'm afraid as I audited the entire autodetector modue for add_operation
calls passing dependencies
(which are the ones adding _auto_deps
) and also used type checking and found no violations. At this point I suspect you might use a third-party app that overrides the migrate
management command.
comment:5 by , 4 months ago
If it helps, this is the value causing the issue which get passed as dependency parameters: ('audit_log', 'requestauditlog', 'content_type', True)
Maybe it's only the case when using the contenttype framework:
content_type = models.ForeignKey( ContentType, on_delete=models.CASCADE, verbose_name=_('Content type'), blank=True, null=True, ) object_id = models.PositiveBigIntegerField( verbose_name=_('Object ID'), help_text=_('ID of the object to link'), blank=True, null=True, )
comment:6 by , 4 months ago
Ok the issue comes from django-pgtrigger, the latest version fixes the operations list and this seems to work.
I'm sorry for the inconvenience, thanks for your help, much appreciated.
Setting
MIGRATION_MODULES = DisableMigrations()
is not a supported pattern.I assume you ported it over from ticket:25388#comment:20 which eventually resulted in the addition of the
TEST["MIGRATE"]
setting which should now be used instead.Please re-open if you can reproduce without using the
DisableMigrations
pattern.