Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to deal with DB migration while using South, Django and Git?

Background :-

I am using Django 1.3. We are using South as the module for DB migration and Git SCM.

Problem:-

What is the correct way to deal with the migrations Folder that is formed?

The main problem is I make changes in the DB schema in the development machine, when I upload it to the production server I have to migrate the existing schema. While doing that there is always some issue with the migration files.

Should I just add the migrations folder to the gitignore ? or is there a better way to go about it ?

like image 635
Akamad007 Avatar asked Apr 10 '12 04:04

Akamad007


People also ask

What is South migration in Django?

South is a migration tool used with Django. There will be times when you would be adding fields to a model or changing the type of field (eg: Field was an IntegerField and you want to change it to FloatField). In such cases syncdb doesn't help and South comes to your rescue.

Which command is used for migration in Django?

The Commands There are several commands which you will use to interact with migrations and Django's handling of database schema: migrate , which is responsible for applying and unapplying migrations. makemigrations , which is responsible for creating new migrations based on the changes you have made to your models.


1 Answers

You should add the migrations folder to your version control system and use the same files for production and development. You may run into some problems on your production system if you introduced your migrations not from the beginning and you have already existing tables.

Therefore you have to fake the first migration, which normally does the same thing as syncdb did when you created your database for the first time. So when trying to apply migrations for your app for the first time on the production machine, execute manage.py migrate app_name 0001 --fake. This lets South know, that the first migration has already been applied (which already happend with syncdb) and when you run migrate again, it would continue with the following migrations.

like image 50
Bernhard Vallant Avatar answered Oct 13 '22 17:10

Bernhard Vallant