I’ve ported my schema evolution work from my SoC project last summer to Django v0.96. To use it, download the patch below, and run the following:
$ cd /<path_to_python_dir>/site-packages/django/
$ patch -p1 < ~/<download_dir>/django_schema_evolution-v096patch.txt
It should output the following:
patching file core/management.py
patching file db/backends/mysql/base.py
patching file db/backends/mysql/introspection.py
patching file db/backends/postgresql/base.py
patching file db/backends/postgresql/introspection.py
patching file db/backends/sqlite3/base.py
patching file db/backends/sqlite3/introspection.py
patching file db/models/fields/__init__.py
patching file db/models/options.py
To use it:
$ cd /<path_to_project_dir>/
$ ./manage.py sqlevolve <app_name>
It should output something like this:
BEGIN;
ALTER TABLE `main_query` CHANGE COLUMN `accuracy` `accuracynew` numeric(10, 6) NULL;
ALTER TABLE `main_query` ADD COLUMN `price` varchar(256) NULL;
COMMIT;
Assuming you have a model such as this:
class Query(models.Model):
query = models.CharField(maxlength=256, blank=False)
accuracynew = models.FloatField(max_digits=10, decimal_places=6, null=True, blank=True, aka='accuracy')
price = models.CharField(maxlength=256, null=True, blank=True) # new column
Note the aka field where I changed the name of “accuracy” to “accuracynew”.
Source code:
Documentation:
Let me know if you find any bugs.