| 1 |
from django.core.checks import Error, Tags, register |
| 2 |
|
| 3 |
|
| 4 |
@register(Tags.commands) |
| 5 |
def migrate_and_makemigrations_autodetector(**kwargs): |
| 6 |
from django.core.management import get_commands, load_command_class |
| 7 |
|
| 8 |
commands = get_commands() |
| 9 |
|
| 10 |
make_migrations = load_command_class(commands["makemigrations"], "makemigrations") |
| 11 |
migrate = load_command_class(commands["migrate"], "migrate") |
| 12 |
|
| 13 |
if make_migrations.autodetector is not migrate.autodetector: |
| 14 |
return [ |
| 15 |
Error( |
| 16 |
"The migrate and makemigrations commands must have the same " |
| 17 |
"autodetector.", |
| 18 |
hint=( |
| 19 |
f"makemigrations.Command.autodetector is " |
| 20 |
f"{make_migrations.autodetector.__name__}, but " |
| 21 |
f"migrate.Command.autodetector is " |
| 22 |
f"{migrate.autodetector.__name__}." |
| 23 |
), |
| 24 |
id="commands.E001", |
| 25 |
) |
| 26 |
] |
| 27 |
|
| 28 |
return [] |