#34988: Makemigrations shouldn't prompt for default values for non-nullable 
fields
of other apps.
-----------------------------------------+--------------------------------
               Reporter:  Sarah Boyce    |          Owner:  nobody
                   Type:  Uncategorized  |         Status:  new
              Component:  Migrations     |        Version:  dev
               Severity:  Normal         |       Keywords:  makemigrations
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+--------------------------------
 Have more than one app (app_1 and app_2). In app_1 have a model that has
 it's migrations applied then add a field that doesn't have a default and
 is not nullable (do not run makemigrations).
 Then add a new model (or anything that would require a migration) to
 app_2.
 Run `manage.py makemigrations app_2`

 You get prompted for every app that has unapplied migrations missing
 defaults even though you're running migrations for a different app.
 I would expect it not to care, as you can input temporary defaults to all
 these other apps and it doesn't do anything with them.

 I think this might be a test case:

 {{{
 diff --git a/tests/migrations/test_commands.py
 b/tests/migrations/test_commands.py
 index a9c1cdf893..518ebef872 100644
 --- a/tests/migrations/test_commands.py
 +++ b/tests/migrations/test_commands.py
 @@ -1979,6 +1979,39 @@ class MakeMigrationsTests(MigrationTestBase):
          self.assertIn("Remove field silly_field from sillymodel",
 out.getvalue())
          self.assertIn("Add field silly_rename to sillymodel",
 out.getvalue())

 +    @override_settings(
 +        INSTALLED_APPS=[
 +            "migrations",
 +            "migrations.migrations_test_apps.migrated_app",
 +        ]
 +    )
 +    def
 
test_makemigrations_interactive_not_null_addition_multiple_apps_single_call(self):
 +        class Author(models.Model):
 +            silly_author_field = models.BooleanField(null=False)
 +
 +            class Meta:
 +                app_label = "migrations"
 +
 +        class NewModel1(models.Model):
 +            class Meta:
 +                app_label = "migrated_app"
 +
 +        input_msg = (
 +            "It is impossible to add a non-nullable field
 'silly_author_field' to "
 +            "author without specifying a default. This is because the "
 +            "database needs something to populate existing rows.\n"
 +            "Please select a fix:\n"
 +            " 1) Provide a one-off default now (will be set on all
 existing "
 +            "rows with a null value for this column)\n"
 +            " 2) Quit and manually define a default value in models.py."
 +        )
 +        with
 self.temporary_migration_module(module="migrations.test_migrations"):
 +            with mock.patch("builtins.input", return_value="1"):
 +                with captured_stdout() as out:
 +                    call_command("makemigrations", "migrated_app",
 interactive=True)
 +            output = out.getvalue()
 +            self.assertNotIn(input_msg, output)
 +
      @mock.patch("builtins.input", return_value="Y")
      def test_makemigrations_model_rename_interactive(self, mock_input):
          class RenamedModel(models.Model):
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34988>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018bf7179a9f-683b34e4-dbf4-4d59-86fa-1f757d8d4c19-000000%40eu-central-1.amazonses.com.

Reply via email to