There is an entire section on legacy databases in Django documentation and rightly so, as you will run into them many times. Data is more important than code, and databases are the repositories of data in most enterprises.
You can modernize a legacy application written in other languages or frameworks by importing their database structure into Django. As an immediate advantage, you can use the Django admin interface to view and change your legacy data.
Django makes this easy with the inspectdb
management command, which looks as follows:
$ python manage.py inspectdb > models.py
This command, if run while your settings are configured to use the legacy database, can automatically generate the Python code that would go into your models file.
Here are some best practices if you are using this approach to integrate to a legacy database:
ID
' fields since Django creates them automatically. _id
).django_*
and auth_*
) in the legacy database.In an ideal world, your auto-generated models would immediately start working, but in practice, it takes a lot of trial and error. Sometimes, the data type that Django inferred might not match your expectations. In other cases, you might want to add additional meta information such as
unique_together
to your model.
Eventually, you should be able to see all the data that was locked inside that aging PHP application in your familiar Django admin interface. I am sure this will bring a smile to your face.