27

I quite like Rails' database migration management system. It is not 100% perfect, but it does the trick. Django does not ship with such a database migration system (yet?) but there are a number of open source projects to do just that, such as django-evolution and south for example.

So I am wondering, what database migration management solution for django do you prefer? (one option per answer please)

Marcin
  • 44,601
  • 17
  • 110
  • 191
MiniQuark
  • 40,659
  • 30
  • 140
  • 167
  • Django ships a migration tool as of 1.7. Although there seem to be others still kicking such as [simple-db-migrate](https://github.com/guilhermechapiewski/simple-db-migrate), the leading alternative, [South](http://south.aeracode.org/), now points to Django's built-in migration tool. – Ben Creasy Jan 20 '17 at 11:46

8 Answers8

22

I've been using South, but Migratory looks promising as well.

akaihola
  • 24,161
  • 5
  • 52
  • 64
9

Migratory looks nice and simple.

mcella
  • 139
  • 3
  • 7
    As of September 2010, Migratory seems to be dead. No source commits since January 2009, and it's expecting stuff in Django which is no longer there in the most recent release. – Simon Sep 23 '10 at 11:07
4

If you are using SQLAlchemy as your ORM then the de facto standard is Alembic.

Another alternative that haven't been mentioned is yoyo-migrations.

cwadding
  • 809
  • 8
  • 14
3

We use Django at work, and we've been using dmigrations. While it has its quirks, it's been useful so far. Some features:

  • It uses a table in the database to keep track of which migrations have been applied.
  • Because it knows which ones have been applied, you can migrate up and back down.
  • It integrates with manage.py as a command.
  • The individual migration scripts are Python, but if your migration logic is pure SQL, dmigrations makes it easy to just can the SQL and have it executed.

One problem is that it only currently supports MySQL. However, one of our guys make a local hack to it to support PostgreSQL, which we use. As I recall, the hack wasn't all that extensive, so it shouldn't be terribly difficult to hack it up to support other RDBMSs.

Brian Clapper
  • 23,437
  • 6
  • 62
  • 65
2

I like django-evolution:

pros:

  • clean design
  • no SQL needed
  • flexible
  • trivial to install
  • easy to use

cons:

  • migrations are not fixed in the codebase
  • a risk exists of accidently running a migration twice
MiniQuark
  • 40,659
  • 30
  • 140
  • 167
  • I don't think it's possible in the normal workflow to run a migration twice. When I run manage.py evolve --hint --execute, it applies the changes, running it second time does nothing. – Tomas Andrle Sep 02 '09 at 17:23
1

Besides South, dmigrations, django-evolution, and Migratory I thought I would add simplemigrations as another tool I've seen for automating Django migrations.

I've used three of these in the past but do migrations by hand now. I'm thinking about trying South again due to the latest features added.

Van Gale
  • 41,789
  • 9
  • 67
  • 78
1

Just to note that since 2009, pretty much every project mentioned here other than South is dead. South is the de facto standard, for better or worse.

Marcin
  • 44,601
  • 17
  • 110
  • 191
  • 2
    South hasn't had any updates now for some time and the link you posted for their domain is down. Would you still consider it the de facto standard? – cwadding Jan 29 '16 at 20:13
  • @cwadding No, I'd consider Django's built-in migrations the standard. – Marcin Jan 29 '16 at 21:59
  • What if you were not creating a Django App but just needed the ORM and migrations? Would you still use Django's built-in migrations? – cwadding Feb 01 '16 at 16:41
  • @cwadding Migrations are for the ORM. – Marcin Feb 01 '16 at 17:44
0

I've been using simple-db-migrate

Pros:

  • it allows me to rollback the migrations (IDK if other do this too).
  • integrates with manage.py
  • everyone that knows SQL can create a migration
  • it doesn't run a migration twice: the application writes the migration information(timestamp, query, etc.) on a table

Cons:

  • if you add a migration with a lower timestamp than the latest migration installed, this migration doesn't run
  • Only MySQL is supported
mondaini
  • 77
  • 8