Fixed #25239 -- Corrected makemigrations numbering if a migration has a number-only filename.
This commit is contained in:
parent
52a190b657
commit
de41fbb3cf
|
@ -1154,6 +1154,7 @@ class MigrationAutodetector(object):
|
||||||
Given a migration name, tries to extract a number from the
|
Given a migration name, tries to extract a number from the
|
||||||
beginning of it. If no number found, returns None.
|
beginning of it. If no number found, returns None.
|
||||||
"""
|
"""
|
||||||
if re.match(r"^\d+_", name):
|
match = re.match(r'^\d+', name)
|
||||||
return int(name.split("_")[0])
|
if match:
|
||||||
|
return int(match.group())
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -510,6 +510,19 @@ class MakeMigrationsTests(MigrationTestBase):
|
||||||
self.assertIn('\\xda\\xd1\\xcd\\xa2\\xd3\\xd0\\xc9', content) # title.verbose_name
|
self.assertIn('\\xda\\xd1\\xcd\\xa2\\xd3\\xd0\\xc9', content) # title.verbose_name
|
||||||
self.assertIn('\\u201c\\xd0j\\xe1\\xf1g\\xf3\\u201d', content) # title.default
|
self.assertIn('\\u201c\\xd0j\\xe1\\xf1g\\xf3\\u201d', content) # title.default
|
||||||
|
|
||||||
|
def test_makemigrations_order(self):
|
||||||
|
"""
|
||||||
|
makemigrations should recognize number-only migrations (0001.py).
|
||||||
|
"""
|
||||||
|
module = 'migrations.test_migrations_order'
|
||||||
|
with self.temporary_migration_module(module=module) as migration_dir:
|
||||||
|
if hasattr(importlib, 'invalidate_caches'):
|
||||||
|
# Python 3 importlib caches os.listdir() on some platforms like
|
||||||
|
# Mac OS X (#23850).
|
||||||
|
importlib.invalidate_caches()
|
||||||
|
call_command('makemigrations', 'migrations', '--empty', '-n', 'a', '-v', '0')
|
||||||
|
self.assertTrue(os.path.exists(os.path.join(migration_dir, '0002_a.py')))
|
||||||
|
|
||||||
def test_failing_migration(self):
|
def test_failing_migration(self):
|
||||||
# If a migration fails to serialize, it shouldn't generate an empty file. #21280
|
# If a migration fails to serialize, it shouldn't generate an empty file. #21280
|
||||||
apps.register_model('migrations', UnserializableModel)
|
apps.register_model('migrations', UnserializableModel)
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
]
|
Loading…
Reference in New Issue