Django manage.py --no-input . Yes or no?
Asked Answered
S

1

25

I can't find this in the docs. When I run python manage.py collecstatic --no-input does it mean it will answer "yes" to any prompt that would pop up in the process? The same for python manage.py migrate --no-input.

Scotney answered 30/1, 2017 at 18:43 Comment(1)
I think generally, it's to answer yes, but I've noticed before bugs with it failing to remove stale content types. code.djangoproject.com/ticket/25036Enthuse
D
41

For collectstatic:

    message.append(
        'Are you sure you want to do this?\n\n'
        "Type 'yes' to continue, or 'no' to cancel: "
    )

    if self.interactive and input(''.join(message)) != 'yes':
        raise CommandError("Collecting static files cancelled.")

So for collect static, if you set --no-input it will set interactive to False and, as you can see above, will answer yes to the question for you.

For migrate it is much trickier because of django signaling. The migrate management itself does not ask any questions, but other installed apps may hook into the pre_migrate_signal or post_migrate_signal and handle interactivity in their own way. The most common one I know of is contenttypes

For contenttypes, --no-input answers "no" as in "No, please don't delete any stale contenttypes":

        if interactive:
            content_type_display = '\n'.join(
                '    %s | %s' % (ct.app_label, ct.model)
                for ct in to_remove
            )
            ok_to_delete = input("""The following content types are stale and need to be deleted:

%s

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.

    Type 'yes' to continue, or 'no' to cancel: """ % content_type_display)
        else:
            ok_to_delete = False
Demise answered 31/1, 2017 at 6:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.