#29831: Add validation on the `--name` argument in makemigrations -------------------------------------+------------------------------------- Reporter: Maxime | Owner: nobody Lorant | Type: | Status: new Cleanup/optimization | Component: | Version: 2.1 Migrations | Keywords: migrations name Severity: Normal | makemigrations Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 1 UI/UX: 0 | -------------------------------------+------------------------------------- After creating a new empty migration, I got an error when applying it. The error is pretty clear when you have the context but can be misleading for beginners: I created a migration containing a dot in its name so Django has split the migration and fails to import the module somehow.
{{{ $ python manage.py makemigrations myapp --empty -n "remove_foo.bar_thing" Migrations for 'myapp': myproject/myapp/migrations/0085_remove_foo.bar_thing.py ^ notice the dot here $ python manage.py migrate Traceback (most recent call last): File "manage.py", line 6, in <module> execute_from_command_line(sys.argv) File "/data/.virtualenvs/MY_VENV/lib/python3.5/site- packages/django/core/management/__init__.py", line 371, in execute_from_command_line utility.execute() File "/data/.virtualenvs/MY_VENV/lib/python3.5/site- packages/django/core/management/__init__.py", line 365, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/data/.virtualenvs/MY_VENV/lib/python3.5/site- packages/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **cmd_options) File "/data/.virtualenvs/MY_VENV/lib/python3.5/site- packages/django/core/management/base.py", line 335, in execute output = self.handle(*args, **options) File "/data/.virtualenvs/MY_VENV/lib/python3.5/site- packages/django/core/management/commands/migrate.py", line 79, in handle executor = MigrationExecutor(connection, self.migration_progress_callback) File "/data/.virtualenvs/MY_VENV/lib/python3.5/site- packages/django/db/migrations/executor.py", line 18, in __init__ self.loader = MigrationLoader(self.connection) File "/data/.virtualenvs/MY_VENV/lib/python3.5/site- packages/django/db/migrations/loader.py", line 49, in __init__ self.build_graph() File "/data/.virtualenvs/MY_VENV/lib/python3.5/site- packages/django/db/migrations/loader.py", line 201, in build_graph self.load_disk() File "/data/.virtualenvs/MY_VENV/lib/python3.5/site- packages/django/db/migrations/loader.py", line 110, in load_disk migration_module = import_module("%s.%s" % (module_name, migration_name)) File "/data/.virtualenvs/MY_VENV/lib/python3.5/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 986, in _gcd_import File "<frozen importlib._bootstrap>", line 969, in _find_and_load File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 986, in _gcd_import File "<frozen importlib._bootstrap>", line 969, in _find_and_load File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked ImportError: No module named 'myproject.myapp.migrations.0085_remove_foo' }}} I suggest to add a validation step that fails when the migration name supplied with the `-n/--name` argument contains dots (and why not spaces too?). To be honest, I only tried this on Django 2.0.x, but I did not see any changes about this problem in Django 2.1 releases notes. -- Ticket URL: <https://code.djangoproject.com/ticket/29831> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/050.b307a2d9774fc231b687532e1020ea26%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.