Book Image

Django Design Patterns and Best Practices

By : Arun Ravindran
Book Image

Django Design Patterns and Best Practices

By: Arun Ravindran

Overview of this book

Table of Contents (19 chapters)
Django Design Patterns and Best Practices
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Migrations


Migrations help you to confidently make changes to your models. Introduced in Django 1.7, migrations are an essential and easy-to-use parts of a development workflow.

The new workflow is essentially as follows:

  1. The first time you define your model classes, you will need to run:

    python manage.py makemigrations <app_label>
    
  2. This will create migration scripts in app/migrations folder.

  3. Run the following command in the same (development) environment:

    python manage.py migrate <app_label>
    

    This will apply the model changes to the database. Sometimes, questions are asked to handle the default values, renaming, and so on.

  4. Propagate the migration scripts to other environments. Typically, your version control tool, for example Git, will take care of this. As the latest source is checked out, the new migration scripts will also appear.

  5. Run the following command in these environments to apply the model changes:

    python manage.py migrate <app_label>
    
  6. Whenever you make changes to the...