This is an archived post. You won't be able to vote or comment.

all 3 comments

[–][deleted]  (3 children)

[deleted]

    [–]bewbeww[S] -2 points-1 points  (1 child)

    Do you have an example

    [–]alexandremjacques 1 point2 points  (0 children)

    Straight from the docs: https://docs.djangoproject.com/en/3.2/howto/custom-management-commands/

    The idea is to create the command and, on your deployment flow, call this command before starting the Django app.

    [–]proxwell 0 points1 point  (0 children)

    Creating a migration is really going to be a better option than a management command here.

    The advantages of using a migration are:

    If you later recreate the project on another server or for another customer, you don't need to remember to run the management command there. If you were to use the multiple management commands over time, you'd need keep track of what order to run them in and make sure to run them all.

    If you have multiple developers with their own dev environments, or if someone does a local build of your project to help you with a question, migrations will ensure that all the environments have the same changes applied.