Django 1.7 Migrations – Simple Example of Use

Hi there, since Django 1.7 release is coming soon, I decided to take some time and learn how the workflow will be when working with these Migrations, and decided to share my experience with you.



New Commands

So, first of all we have the

./manage.py migrate

that replaces the old

./manage.py syncdb

This is the command that will execute the migrations, and create the initial Django tables (for auth, session and etc). But you should see now that the superuser for the DB is not created with this.
So you have to create it using the command:

./manage.py createsuperuser

Another command that appeared is the

./manage.py makemigrations

and he is the one that will create the migration files representing the changes in your models.py.

So the basic idea is:

  1. Modify models.py
  2. Make the migration with: makemigrations
  3. Execute the migration with: migrate

A Workflow Example

I created a git repository(django-17-migrations-example) that has a simple workflow of what you’ll probably face when doing your projects.

In it you’ll be see a simple Polls app using migration, all you have to do is navigate through the commits and execute the migrations.
I use Scheme Migrations and Data Migrations, and also implement a simple rollback for a custom made migration.

You can check the complete workflow and let it guide you, in the Readme of the project.

That’s it guys.
Good migrations for you.

About arruda

Adoro programar, descobrir novas frameworks ágeis e suas diversas aplicações.