Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can stale content types be automatically deleted in Django?

I'm working with a PyQt application which uses Django to deliver it's content to desktop users.

In the latest update we have stale content types stored in the database by Django and on startup of the application South's migrate or syncdb offers to delete them. Is it possible to do something with the call to migrate/syncdb that automatically deletes these?

This prompt can't be exposed to the end user for obvious reasons, so I really hope there is some way we can take car of this automatically :)

I've seen that with the South migrate you can call --noinput but that doesn't delete them, and it'd be good if we could do that as we know it'll be safe.

like image 595
markwalker_ Avatar asked Sep 18 '13 10:09

markwalker_


2 Answers

On unix systems there is a command yes, which will repeatedly output a string to stdout, separated by newlines. We can use this to auto-answer this prompt.

yes "yes" | python ./manage.py migrate

like image 145
Andrew Farrell Avatar answered Oct 16 '22 03:10

Andrew Farrell


I use this command to automatically answer yes in my scripts when I'm doing Django migrations:

cat <(echo "yes") - | ./manage.py syncdb --migrate

Note that this only takes care of the first prompt. You can read more about the details of how this works and how to add an automatic answer to a second prompt here:

https://stackoverflow.com/a/16347534/1636882

like image 29
Ben Konrath Avatar answered Oct 16 '22 02:10

Ben Konrath