File: commands.py

package info (click to toggle)
python-django 3%3A6.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 61,992 kB
  • sloc: python: 371,353; javascript: 19,376; xml: 211; makefile: 187; sh: 28
file content (28 lines) | stat: -rw-r--r-- 965 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from django.core.checks import Error, Tags, register


@register(Tags.commands)
def migrate_and_makemigrations_autodetector(**kwargs):
    from django.core.management import get_commands, load_command_class

    commands = get_commands()

    make_migrations = load_command_class(commands["makemigrations"], "makemigrations")
    migrate = load_command_class(commands["migrate"], "migrate")

    if make_migrations.autodetector is not migrate.autodetector:
        return [
            Error(
                "The migrate and makemigrations commands must have the same "
                "autodetector.",
                hint=(
                    f"makemigrations.Command.autodetector is "
                    f"{make_migrations.autodetector.__name__}, but "
                    f"migrate.Command.autodetector is "
                    f"{migrate.autodetector.__name__}."
                ),
                id="commands.E001",
            )
        ]

    return []