Um Blog Sobre Tecnologia, Informação, Literatura e Coisas da Vida

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

``` {lang="shell"} ./ migrate

that replaces the old

``` {lang="shell"}
./ 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:

``` {lang="shell"} ./ createsuperuser

Another command that appeared is the

``` {lang="shell"}
./ makemigrations

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

So the basic idea is:

  1. Modify
  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.