Fixed #29831 -- Added validation for makemigrations --name.
This commit is contained in:
parent
136a900ef9
commit
10d82c85aa
|
@ -61,6 +61,8 @@ class Command(BaseCommand):
|
|||
self.merge = options['merge']
|
||||
self.empty = options['empty']
|
||||
self.migration_name = options['name']
|
||||
if self.migration_name and not self.migration_name.isidentifier():
|
||||
raise CommandError('The migration name must be a valid Python identifier.')
|
||||
check_changes = options['check_changes']
|
||||
|
||||
# Make sure the app they asked for exists
|
||||
|
|
|
@ -756,7 +756,8 @@ Enables fixing of migration conflicts.
|
|||
|
||||
.. django-admin-option:: --name NAME, -n NAME
|
||||
|
||||
Allows naming the generated migration(s) instead of using a generated name.
|
||||
Allows naming the generated migration(s) instead of using a generated name. The
|
||||
name must be a valid Python :ref:`identifier <python:identifiers>`.
|
||||
|
||||
.. django-admin-option:: --check
|
||||
|
||||
|
|
|
@ -1352,6 +1352,11 @@ class MakeMigrationsTests(MigrationTestBase):
|
|||
self.assertIn("dependencies=[\n('migrations','0001_%s'),\n]" % migration_name_0001, content)
|
||||
self.assertIn("operations=[\n]", content)
|
||||
|
||||
def test_makemigrations_with_invalid_custom_name(self):
|
||||
msg = 'The migration name must be a valid Python identifier.'
|
||||
with self.assertRaisesMessage(CommandError, msg):
|
||||
call_command('makemigrations', 'migrations', '--name', 'invalid name', '--empty')
|
||||
|
||||
def test_makemigrations_check(self):
|
||||
"""
|
||||
makemigrations --check should exit with a non-zero status when
|
||||
|
|
Loading…
Reference in New Issue