Yikes! Migrations are hard.
First off, make a backup of your database that you can test with (this is probably a given, but it needs to be stated.) You can in fact use mysqldump
to dump straight to a new MySQL database.
Most of what will get you started is in Django's documentation for working with "legacy databases".
Roughly speaking, set up a Django application with your database connection parameters and the name of the database. You'll need to edit the DATABASES
setting and assign values to these keys:
NAME
ENGINE
USER
PASSWORD
HOST
PORT
To get started, there is a built in utility called inspectdb
that can generate models based on your database.
python manage.py inspectdb
Keep in mind that this is only a first pass, and you'll likely have to fix some of it by hand. Once you get the output cleaned up, save it as models.py and add it to your INSTALLED_APPS
setting. You'll also need to set managed=True
in each of your model's internal class Meta
.
After all this is done, run
python manage.py migrate
You will probably have to tweak this over and over to get it right. I highly recommend having backups and a good (maybe automated) setup to keep testing and tweaking to get it right.