test_commands.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import codecs
  4. import os
  5. import shutil
  6. from django.apps import apps
  7. from django.db import connection, models
  8. from django.core.management import call_command, CommandError
  9. from django.db.migrations import questioner
  10. from django.test import override_settings, override_system_checks
  11. from django.utils import six
  12. from django.utils._os import upath
  13. from django.utils.encoding import force_text
  14. from .models import UnicodeModel, UnserializableModel
  15. from .test_base import MigrationTestBase
  16. class MigrateTests(MigrationTestBase):
  17. """
  18. Tests running the migrate command.
  19. """
  20. # `auth` app is imported, but not installed in these tests (thanks to
  21. # MigrationTestBase), so we need to exclude checks registered by this app.
  22. @override_system_checks([])
  23. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
  24. def test_migrate(self):
  25. """
  26. Tests basic usage of the migrate command.
  27. """
  28. # Make sure no tables are created
  29. self.assertTableNotExists("migrations_author")
  30. self.assertTableNotExists("migrations_tribble")
  31. self.assertTableNotExists("migrations_book")
  32. # Run the migrations to 0001 only
  33. call_command("migrate", "migrations", "0001", verbosity=0)
  34. # Make sure the right tables exist
  35. self.assertTableExists("migrations_author")
  36. self.assertTableExists("migrations_tribble")
  37. self.assertTableNotExists("migrations_book")
  38. # Run migrations all the way
  39. call_command("migrate", verbosity=0)
  40. # Make sure the right tables exist
  41. self.assertTableExists("migrations_author")
  42. self.assertTableNotExists("migrations_tribble")
  43. self.assertTableExists("migrations_book")
  44. # Unmigrate everything
  45. call_command("migrate", "migrations", "zero", verbosity=0)
  46. # Make sure it's all gone
  47. self.assertTableNotExists("migrations_author")
  48. self.assertTableNotExists("migrations_tribble")
  49. self.assertTableNotExists("migrations_book")
  50. @override_system_checks([])
  51. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
  52. def test_migrate_list(self):
  53. """
  54. Tests --list output of migrate command
  55. """
  56. stdout = six.StringIO()
  57. call_command("migrate", list=True, stdout=stdout, verbosity=0)
  58. self.assertIn("migrations", stdout.getvalue().lower())
  59. self.assertIn("[ ] 0001_initial", stdout.getvalue().lower())
  60. self.assertIn("[ ] 0002_second", stdout.getvalue().lower())
  61. call_command("migrate", "migrations", "0001", verbosity=0)
  62. stdout = six.StringIO()
  63. # Giving the explicit app_label tests for selective `show_migration_list` in the command
  64. call_command("migrate", "migrations", list=True, stdout=stdout, verbosity=0)
  65. self.assertIn("migrations", stdout.getvalue().lower())
  66. self.assertIn("[x] 0001_initial", stdout.getvalue().lower())
  67. self.assertIn("[ ] 0002_second", stdout.getvalue().lower())
  68. # Cleanup by unmigrating everything
  69. call_command("migrate", "migrations", "zero", verbosity=0)
  70. @override_system_checks([])
  71. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_conflict"})
  72. def test_migrate_conflict_exit(self):
  73. """
  74. Makes sure that migrate exits if it detects a conflict.
  75. """
  76. with self.assertRaises(CommandError):
  77. call_command("migrate", "migrations")
  78. @override_system_checks([])
  79. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
  80. def test_sqlmigrate(self):
  81. """
  82. Makes sure that sqlmigrate does something.
  83. """
  84. # Make sure the output is wrapped in a transaction
  85. stdout = six.StringIO()
  86. call_command("sqlmigrate", "migrations", "0001", stdout=stdout)
  87. output = stdout.getvalue()
  88. self.assertIn(connection.ops.start_transaction_sql(), output)
  89. self.assertIn(connection.ops.end_transaction_sql(), output)
  90. # Test forwards. All the databases agree on CREATE TABLE, at least.
  91. stdout = six.StringIO()
  92. call_command("sqlmigrate", "migrations", "0001", stdout=stdout)
  93. self.assertIn("create table", stdout.getvalue().lower())
  94. # Cannot generate the reverse SQL unless we've applied the migration.
  95. call_command("migrate", "migrations", verbosity=0)
  96. # And backwards is a DROP TABLE
  97. stdout = six.StringIO()
  98. call_command("sqlmigrate", "migrations", "0001", stdout=stdout, backwards=True)
  99. self.assertIn("drop table", stdout.getvalue().lower())
  100. # Cleanup by unmigrating everything
  101. call_command("migrate", "migrations", "zero", verbosity=0)
  102. @override_system_checks([])
  103. @override_settings(
  104. INSTALLED_APPS=[
  105. "migrations.migrations_test_apps.migrated_app",
  106. "migrations.migrations_test_apps.migrated_unapplied_app",
  107. "migrations.migrations_test_apps.unmigrated_app"])
  108. def test_regression_22823_unmigrated_fk_to_migrated_model(self):
  109. """
  110. https://code.djangoproject.com/ticket/22823
  111. Assuming you have 3 apps, `A`, `B`, and `C`, such that:
  112. * `A` has migrations
  113. * `B` has a migration we want to apply
  114. * `C` has no migrations, but has an FK to `A`
  115. When we try to migrate "B", an exception occurs because the
  116. "B" was not included in the ProjectState that is used to detect
  117. soft-applied migrations.
  118. """
  119. stdout = six.StringIO()
  120. call_command("migrate", "migrated_unapplied_app", stdout=stdout)
  121. class MakeMigrationsTests(MigrationTestBase):
  122. """
  123. Tests running the makemigrations command.
  124. """
  125. # Because the `import_module` performed in `MigrationLoader` will cache
  126. # the migrations package, we can't reuse the same migration package
  127. # between tests. This is only a problem for testing, since `makemigrations`
  128. # is normally called in its own process.
  129. creation_counter = 0
  130. def setUp(self):
  131. MakeMigrationsTests.creation_counter += 1
  132. self._cwd = os.getcwd()
  133. self.test_dir = os.path.abspath(os.path.dirname(upath(__file__)))
  134. self.migration_dir = os.path.join(self.test_dir, 'migrations_%d' % self.creation_counter)
  135. self.migration_pkg = "migrations.migrations_%d" % self.creation_counter
  136. self._old_models = apps.app_configs['migrations'].models.copy()
  137. def tearDown(self):
  138. apps.app_configs['migrations'].models = self._old_models
  139. apps.all_models['migrations'] = self._old_models
  140. apps.clear_cache()
  141. os.chdir(self.test_dir)
  142. try:
  143. self._rmrf(self.migration_dir)
  144. except OSError:
  145. pass
  146. try:
  147. self._rmrf(os.path.join(self.test_dir,
  148. "test_migrations_path_doesnt_exist"))
  149. except OSError:
  150. pass
  151. os.chdir(self._cwd)
  152. def _rmrf(self, dname):
  153. if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir:
  154. return
  155. shutil.rmtree(dname)
  156. # `auth` app is imported, but not installed in this test (thanks to
  157. # MigrationTestBase), so we need to exclude checks registered by this app.
  158. @override_system_checks([])
  159. def test_files_content(self):
  160. self.assertTableNotExists("migrations_unicodemodel")
  161. apps.register_model('migrations', UnicodeModel)
  162. with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}):
  163. call_command("makemigrations", "migrations", verbosity=0)
  164. init_file = os.path.join(self.migration_dir, "__init__.py")
  165. # Check for existing __init__.py file in migrations folder
  166. self.assertTrue(os.path.exists(init_file))
  167. with open(init_file, 'r') as fp:
  168. content = force_text(fp.read())
  169. self.assertEqual(content, '')
  170. initial_file = os.path.join(self.migration_dir, "0001_initial.py")
  171. # Check for existing 0001_initial.py file in migration folder
  172. self.assertTrue(os.path.exists(initial_file))
  173. with codecs.open(initial_file, 'r', encoding='utf-8') as fp:
  174. content = fp.read()
  175. self.assertTrue('# -*- coding: utf-8 -*-' in content)
  176. self.assertTrue('migrations.CreateModel' in content)
  177. if six.PY3:
  178. self.assertTrue('úñí©óðé µóðéø' in content) # Meta.verbose_name
  179. self.assertTrue('úñí©óðé µóðéøß' in content) # Meta.verbose_name_plural
  180. self.assertTrue('ÚÑÍ¢ÓÐÉ' in content) # title.verbose_name
  181. self.assertTrue('“Ðjáñgó”' in content) # title.default
  182. else:
  183. self.assertTrue('\\xfa\\xf1\\xed\\xa9\\xf3\\xf0\\xe9 \\xb5\\xf3\\xf0\\xe9\\xf8' in content) # Meta.verbose_name
  184. self.assertTrue('\\xfa\\xf1\\xed\\xa9\\xf3\\xf0\\xe9 \\xb5\\xf3\\xf0\\xe9\\xf8\\xdf' in content) # Meta.verbose_name_plural
  185. self.assertTrue('\\xda\\xd1\\xcd\\xa2\\xd3\\xd0\\xc9' in content) # title.verbose_name
  186. self.assertTrue('\\u201c\\xd0j\\xe1\\xf1g\\xf3\\u201d' in content) # title.default
  187. # `auth` app is imported, but not installed in this test (thanks to
  188. # MigrationTestBase), so we need to exclude checks registered by this app.
  189. @override_system_checks([])
  190. def test_failing_migration(self):
  191. #21280 - If a migration fails to serialize, it shouldn't generate an empty file.
  192. apps.register_model('migrations', UnserializableModel)
  193. with six.assertRaisesRegex(self, ValueError, r'Cannot serialize'):
  194. with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}):
  195. call_command("makemigrations", "migrations", verbosity=0)
  196. initial_file = os.path.join(self.migration_dir, "0001_initial.py")
  197. self.assertFalse(os.path.exists(initial_file))
  198. @override_system_checks([])
  199. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_conflict"})
  200. def test_makemigrations_conflict_exit(self):
  201. """
  202. Makes sure that makemigrations exits if it detects a conflict.
  203. """
  204. with self.assertRaises(CommandError):
  205. call_command("makemigrations")
  206. @override_system_checks([])
  207. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
  208. def test_makemigrations_merge_no_conflict(self):
  209. """
  210. Makes sure that makemigrations exits if in merge mode with no conflicts.
  211. """
  212. stdout = six.StringIO()
  213. try:
  214. call_command("makemigrations", merge=True, stdout=stdout)
  215. except CommandError:
  216. self.fail("Makemigrations errored in merge mode with no conflicts")
  217. self.assertIn("No conflicts detected to merge.", stdout.getvalue())
  218. @override_system_checks([])
  219. def test_makemigrations_no_app_sys_exit(self):
  220. """
  221. Makes sure that makemigrations exits if a non-existent app is specified.
  222. """
  223. stderr = six.StringIO()
  224. with self.assertRaises(SystemExit):
  225. call_command("makemigrations", "this_app_does_not_exist", stderr=stderr)
  226. self.assertIn("'this_app_does_not_exist' could not be found.", stderr.getvalue())
  227. @override_system_checks([])
  228. def test_makemigrations_empty_no_app_specified(self):
  229. """
  230. Makes sure that makemigrations exits if no app is specified with 'empty' mode.
  231. """
  232. with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}):
  233. self.assertRaises(CommandError, call_command, "makemigrations", empty=True)
  234. @override_system_checks([])
  235. def test_makemigrations_empty_migration(self):
  236. """
  237. Makes sure that makemigrations properly constructs an empty migration.
  238. """
  239. with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}):
  240. try:
  241. call_command("makemigrations", "migrations", empty=True, verbosity=0)
  242. except CommandError:
  243. self.fail("Makemigrations errored in creating empty migration for a proper app.")
  244. initial_file = os.path.join(self.migration_dir, "0001_initial.py")
  245. # Check for existing 0001_initial.py file in migration folder
  246. self.assertTrue(os.path.exists(initial_file))
  247. with codecs.open(initial_file, 'r', encoding='utf-8') as fp:
  248. content = fp.read()
  249. self.assertTrue('# -*- coding: utf-8 -*-' in content)
  250. # Remove all whitespace to check for empty dependencies and operations
  251. content = content.replace(' ', '')
  252. self.assertIn('dependencies=[\n]', content)
  253. self.assertIn('operations=[\n]', content)
  254. @override_system_checks([])
  255. def test_makemigrations_no_changes_no_apps(self):
  256. """
  257. Makes sure that makemigrations exits when there are no changes and no apps are specified.
  258. """
  259. stdout = six.StringIO()
  260. call_command("makemigrations", stdout=stdout)
  261. self.assertIn("No changes detected", stdout.getvalue())
  262. @override_system_checks([])
  263. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_no_changes"})
  264. def test_makemigrations_no_changes(self):
  265. """
  266. Makes sure that makemigrations exits when there are no changes to an app.
  267. """
  268. stdout = six.StringIO()
  269. call_command("makemigrations", "migrations", stdout=stdout)
  270. self.assertIn("No changes detected in app 'migrations'", stdout.getvalue())
  271. @override_system_checks([])
  272. def test_makemigrations_migrations_announce(self):
  273. """
  274. Makes sure that makemigrations announces the migration at the default verbosity level.
  275. """
  276. stdout = six.StringIO()
  277. with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}):
  278. call_command("makemigrations", "migrations", stdout=stdout)
  279. self.assertIn("Migrations for 'migrations'", stdout.getvalue())
  280. @override_system_checks([])
  281. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_no_ancestor"})
  282. def test_makemigrations_no_common_ancestor(self):
  283. """
  284. Makes sure that makemigrations fails to merge migrations with no common ancestor.
  285. """
  286. with self.assertRaises(ValueError) as context:
  287. call_command("makemigrations", "migrations", merge=True)
  288. exception_message = str(context.exception)
  289. self.assertIn("Could not find common ancestor of", exception_message)
  290. self.assertIn("0002_second", exception_message)
  291. self.assertIn("0002_conflicting_second", exception_message)
  292. @override_system_checks([])
  293. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_conflict"})
  294. def test_makemigrations_interactive_reject(self):
  295. """
  296. Makes sure that makemigrations enters and exits interactive mode properly.
  297. """
  298. # Monkeypatch interactive questioner to auto reject
  299. old_input = questioner.input
  300. questioner.input = lambda _: "N"
  301. try:
  302. call_command("makemigrations", "migrations", merge=True, interactive=True, verbosity=0)
  303. merge_file = os.path.join(self.test_dir, 'test_migrations_conflict', '0003_merge.py')
  304. self.assertFalse(os.path.exists(merge_file))
  305. except CommandError:
  306. self.fail("Makemigrations failed while running interactive questioner")
  307. finally:
  308. questioner.input = old_input
  309. @override_system_checks([])
  310. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_conflict"})
  311. def test_makemigrations_interactive_accept(self):
  312. """
  313. Makes sure that makemigrations enters interactive mode and merges properly.
  314. """
  315. # Monkeypatch interactive questioner to auto accept
  316. old_input = questioner.input
  317. questioner.input = lambda _: "y"
  318. stdout = six.StringIO()
  319. try:
  320. call_command("makemigrations", "migrations", merge=True, interactive=True, stdout=stdout)
  321. merge_file = os.path.join(self.test_dir, 'test_migrations_conflict', '0003_merge.py')
  322. self.assertTrue(os.path.exists(merge_file))
  323. os.remove(merge_file)
  324. self.assertFalse(os.path.exists(merge_file))
  325. except CommandError:
  326. self.fail("Makemigrations failed while running interactive questioner")
  327. finally:
  328. questioner.input = old_input
  329. self.assertIn("Created new merge migration", stdout.getvalue())
  330. @override_system_checks([])
  331. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_conflict"})
  332. def test_makemigrations_handle_merge(self):
  333. """
  334. Makes sure that makemigrations properly merges the conflicting migrations with --noinput.
  335. """
  336. stdout = six.StringIO()
  337. call_command("makemigrations", "migrations", merge=True, interactive=False, stdout=stdout)
  338. self.assertIn("Merging migrations", stdout.getvalue())
  339. self.assertIn("Branch 0002_second", stdout.getvalue())
  340. self.assertIn("Branch 0002_conflicting_second", stdout.getvalue())
  341. merge_file = os.path.join(self.test_dir, 'test_migrations_conflict', '0003_merge.py')
  342. self.assertTrue(os.path.exists(merge_file))
  343. os.remove(merge_file)
  344. self.assertFalse(os.path.exists(merge_file))
  345. self.assertIn("Created new merge migration", stdout.getvalue())
  346. @override_system_checks([])
  347. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_no_default"})
  348. def test_makemigrations_dry_run(self):
  349. """
  350. Ticket #22676 -- `makemigrations --dry-run` should not ask for defaults.
  351. """
  352. class SillyModel(models.Model):
  353. silly_field = models.BooleanField(default=False)
  354. silly_date = models.DateField() # Added field without a default
  355. class Meta:
  356. app_label = "migrations"
  357. stdout = six.StringIO()
  358. call_command("makemigrations", "migrations", dry_run=True, stdout=stdout)
  359. # Output the expected changes directly, without asking for defaults
  360. self.assertIn("Add field silly_date to sillymodel", stdout.getvalue())
  361. @override_system_checks([])
  362. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_no_default"})
  363. def test_makemigrations_dry_run_verbosity_3(self):
  364. """
  365. Ticket #22675 -- Allow `makemigrations --dry-run` to output the
  366. migrations file to stdout (with verbosity == 3).
  367. """
  368. class SillyModel(models.Model):
  369. silly_field = models.BooleanField(default=False)
  370. silly_char = models.CharField(default="")
  371. class Meta:
  372. app_label = "migrations"
  373. stdout = six.StringIO()
  374. call_command("makemigrations", "migrations", dry_run=True, stdout=stdout, verbosity=3)
  375. # Normal --dry-run output
  376. self.assertIn("- Add field silly_char to sillymodel", stdout.getvalue())
  377. # Additional output caused by verbosity 3
  378. # The complete migrations file that would be written
  379. self.assertIn("# -*- coding: utf-8 -*-", stdout.getvalue())
  380. self.assertIn("class Migration(migrations.Migration):", stdout.getvalue())
  381. self.assertIn("dependencies = [", stdout.getvalue())
  382. self.assertIn("('migrations', '0001_initial'),", stdout.getvalue())
  383. self.assertIn("migrations.AddField(", stdout.getvalue())
  384. self.assertIn("model_name='sillymodel',", stdout.getvalue())
  385. self.assertIn("name='silly_char',", stdout.getvalue())
  386. @override_system_checks([])
  387. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_path_doesnt_exist.foo.bar"})
  388. def test_makemigrations_migrations_modules_path_not_exist(self):
  389. """
  390. Ticket #22682 -- Makemigrations fails when specifying custom location
  391. for migration files (using MIGRATION_MODULES) if the custom path
  392. doesn't already exist.
  393. """
  394. class SillyModel(models.Model):
  395. silly_field = models.BooleanField(default=False)
  396. class Meta:
  397. app_label = "migrations"
  398. stdout = six.StringIO()
  399. call_command("makemigrations", "migrations", stdout=stdout)
  400. # Command output indicates the migration is created.
  401. self.assertIn(" - Create model SillyModel", stdout.getvalue())
  402. # Migrations file is actually created in the expected path.
  403. self.assertTrue(os.path.isfile(os.path.join(self.test_dir,
  404. "test_migrations_path_doesnt_exist", "foo", "bar",
  405. "0001_initial.py")))
  406. @override_system_checks([])
  407. @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_conflict"})
  408. def test_makemigrations_interactive_by_default(self):
  409. """
  410. Makes sure that the user is prompted to merge by default if there are
  411. conflicts and merge is True. Answer negative to differentiate it from
  412. behavior when --noinput is specified.
  413. """
  414. # Monkeypatch interactive questioner to auto reject
  415. old_input = questioner.input
  416. questioner.input = lambda _: "N"
  417. stdout = six.StringIO()
  418. merge_file = os.path.join(self.test_dir, 'test_migrations_conflict', '0003_merge.py')
  419. try:
  420. call_command("makemigrations", "migrations", merge=True, stdout=stdout)
  421. # This will fail if interactive is False by default
  422. self.assertFalse(os.path.exists(merge_file))
  423. except CommandError:
  424. self.fail("Makemigrations failed while running interactive questioner")
  425. finally:
  426. questioner.input = old_input
  427. if os.path.exists(merge_file):
  428. os.remove(merge_file)
  429. self.assertNotIn("Created new merge migration", stdout.getvalue())
  430. @override_system_checks([])
  431. @override_settings(
  432. MIGRATION_MODULES={"migrations": "migrations.test_migrations_no_changes"},
  433. INSTALLED_APPS=[
  434. "migrations",
  435. "migrations.migrations_test_apps.unspecified_app_with_conflict"])
  436. def test_makemigrations_unspecified_app_with_conflict_no_merge(self):
  437. """
  438. Makes sure that makemigrations does not raise a CommandError when an
  439. unspecified app has conflicting migrations.
  440. """
  441. try:
  442. call_command("makemigrations", "migrations", merge=False, verbosity=0)
  443. except CommandError:
  444. self.fail("Makemigrations fails resolving conflicts in an unspecified app")
  445. @override_system_checks([])
  446. @override_settings(
  447. INSTALLED_APPS=[
  448. "migrations.migrations_test_apps.migrated_app",
  449. "migrations.migrations_test_apps.unspecified_app_with_conflict"])
  450. def test_makemigrations_unspecified_app_with_conflict_merge(self):
  451. """
  452. Makes sure that makemigrations does not create a merge for an
  453. unspecified app even if it has conflicting migrations.
  454. """
  455. # Monkeypatch interactive questioner to auto accept
  456. old_input = questioner.input
  457. questioner.input = lambda _: "y"
  458. stdout = six.StringIO()
  459. merge_file = os.path.join(self.test_dir,
  460. 'migrations_test_apps',
  461. 'unspecified_app_with_conflict',
  462. 'migrations',
  463. '0003_merge.py')
  464. try:
  465. call_command("makemigrations", "migrated_app", merge=True, interactive=True, stdout=stdout)
  466. self.assertFalse(os.path.exists(merge_file))
  467. self.assertIn("No conflicts detected to merge.", stdout.getvalue())
  468. except CommandError:
  469. self.fail("Makemigrations fails resolving conflicts in an unspecified app")
  470. finally:
  471. questioner.input = old_input
  472. if os.path.exists(merge_file):
  473. os.remove(merge_file)