Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django manage.py --no-input . Yes or no?

Tags:

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.

like image 509
Alejandro Veintimilla Avatar asked Jan 30 '17 18:01

Alejandro Veintimilla


1 Answers

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 
like image 58
2ps Avatar answered Sep 19 '22 12:09

2ps