Adapt an existing database to a django app Adapt an existing database to a django app database database

Adapt an existing database to a django app


There is a utility called manage.py inspectdb to generate models from your existing database. It works pretty well.

$ python manage.py inspectdb > models.py


If your database is not very simple -- or very well designed -- you'll find it a poor fit with Django.

While the reverse engineering works well, you may find that the original database design was flawed and you have lots of clumsy workarounds.

The question is one of "legacy software" that works with the old data model.

I'd suggest you do the following.

  1. Design the correct data model, using Django.

  2. Map the correct model to whatever it is you have.

  3. Write a conversion script that uses simple, direct SQL and the Django ORM to migrate data from non-Django-friendly to a better model.

    • If you have legacy software, you'll have to work out an appropriate data movement schedule.

    • If you don't have any legacy software, you'll run this conversion once.