Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you migrate Django models similar to Ruby on Rails migrations?

Django has a number of open source projects that tackle one of the framework's more notable missing features: model "evolution". Ruby on Rails has native support for migrations, but I'm curious if anyone can recommend one of the following Django "evolution" projects:

  • South
  • django-evolution
  • dmigrations
like image 547
Huuuze Avatar asked May 12 '09 15:05

Huuuze


People also ask

What is difference between migrate and migration in Django?

You should think of migrations as a version control system for your database schema. makemigrations is responsible for packaging up your model changes into individual migration files - analogous to commits - and migrate is responsible for applying those to your database.

How do I migrate a specific migration in Rails?

To run a specific migration up or down, use db:migrate:up or db:migrate:down . The version number in the above commands is the numeric prefix in the migration's filename. For example, to migrate to the migration 20160515085959_add_name_to_users. rb , you would use 20160515085959 as the version number.

What are migrations in Ruby on Rails?

Migrations are a convenient way to alter your database schema over time in a consistent way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent. You can think of each migration as being a new 'version' of the database.


4 Answers

South has the most steam behind it. dmigrations is too basic IMO. django-evolution screams if you ever touch the db outside of it.

South is the strongest contender by far. With the model freezing and auto-migrations it's come a long way.

like image 199
tmc Avatar answered Oct 09 '22 20:10

tmc


South and django-evolution are certainly the best options. South's model-freezing and auto-hinting are still quite fragile in my experience (django-evolution's hinting is much more robust in edge cases), but django-evolution's development seems to have mostly stalled since last summer. If I were starting now I'd probably pick South, mostly for that reason.

like image 43
Carl Meyer Avatar answered Oct 09 '22 19:10

Carl Meyer


After reading this, I went from 'knowing nothing about data model evolution' to 'using south to manage model migration' in less than 1 hour. South's documentation is outstanding and got me up to speed in record time. Not having looked at the other tools mentioned, I fully recommend it.

Update: Since posting this answer about a month ago, I went through several data model reviews, ranging from simple field renaming to completely replacing some tables by new ones. South can not do everything in a fully automated manner (e.g. a rename looks like delete & add), but the documentation guides you smoothly through the manual steps.

I will bring south into any future project. Fantastic tool!

like image 2
ssc Avatar answered Oct 09 '22 19:10

ssc


I'm a member of the team that developed dmigrations - but I would wholeheartedly recommend South. It's much more mature, is under active development, and has some killer features like ORM freezing (if you try to use ORM code in dmigrations, then change your models, you're in for a world of pain).

like image 1
Daniel Roseman Avatar answered Oct 09 '22 20:10

Daniel Roseman