Opened 6 years ago
Closed 6 years ago
#29831 closed Cleanup/optimization (fixed)
Add validation on the `--name` argument in makemigrations
Reported by: | Maxime Lorant | Owned by: | Prabakaran Kumaresshan |
---|---|---|---|
Component: | Migrations | Version: | 2.1 |
Severity: | Normal | Keywords: | migrations name makemigrations |
Cc: | Herbert Fortes | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
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.
Change History (7)
follow-up: 4 comment:1 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 6 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 6 years ago
Cc: | added |
---|
follow-up: 5 comment:4 by , 6 years ago
comment:5 by , 6 years ago
Replying to Herbert Fortes:
Replying to Prabakaran Kumaresshan:
Hi,
How are things going?
My first thought is to edit makemigrations and test_commands
I am not pushing. Not at all. I am just talking about the ticket. Feel free.
Hi,
This is my first contribution. I figured the code that needs patch just wondering where to place test scripts, thanks for the link.
I'll do regression and apply patch then let you know.
Much appreciate your help
Replying to Prabakaran Kumaresshan:
Hi,
How are things going?
My first thought is to edit makemigrations and test_commands
I am not pushing. Not at all. I am just talking about the ticket. Feel free.