1👍
Here’s one idea.. read all the disclaimers here first, like which databases are supported for detecting FKs.
https://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-inspectdb
Update: the real answer is to use a mix of the bottom two ideas. Basically, inspectdb is a nice human readable way to figure out the difference between your model and the database. Then, I’d manually build alter table statements to match. Luckily, sqlall
outputs the create statements, so most of it will be cut and paste for new fields.
Make a backup of everything.
- Copy your models.py somewhere.
- Type in
python manage.py inspectdb
- Find the model you’re looking for and paste it into the original models.py
- Set up south.
- Paste the new / updated models.py back into your models.py
- Run schemamigration then migrate.
You can also just do the migrations manually, then convert to south.
python manage.py dbshell
- Describe table (depends on your db)
- Find missing rows… use alter table statements as necessary. (SQL hints in
python manage.py sqlall <myapp>
Source:stackexchange.com