Django: How To Prompt User During Migration?
I'm writing a migration that converts a ForeignKeyField to a ManyToManyField. Part of this migration involves data migration. Migrating forwards is easy and requires no user interaction. Migrating backwards however ideally requires the user to pick which of the m2m to become the foreign key (ie there's a recognition of data loss).
Additionally. the user performing the migration might want to be given a python shell so they can poke around and look at objects before answering the question.
And some users might not care, and might not want to be prompted at all. (ie they use the --no-input argument during migration)
Does django have a built in mechanism to do all this? I can't find anything, but at the back of my mind it seems like something I've seen somewhere.
If you really need to interactively ask for user input during a migration, you can use the
InteractiveMigrationQuestioner in django.db.migrations.questioner.
Subclass it, add your own question (e.g.
ask_which_instance) with its arguments. You can use the
_ask_choice method to let users choose from multiple options.
Then in your
backward() method, instantiate it and call your question method (which should return the user's input, e.g. 1, 2 or 3 if you offer 3 choices).
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module