I basically want to take an existing mysql database structure created and used by a php app (codeigniter framework) and reverse engineer it to a django app. is there some tool to do this? south migrations maybe?
+10
A:
Create a project, and point your settings @ your database
Then run
./manage.py inspectdb
This will print out a python models file for the DB you're pointing at
You can output this to a file by doing something like
./manage.py inspectdb > models.py
And then you can move the file to the most suitable location, and edit it as needed.
Mez
2009-10-09 19:52:57
Good answer. Chapter 18 of the Django Book has further details on using inspectdb to integrate existing databases - http://djangobook.com/en/2.0/chapter18/
Alasdair
2009-10-09 21:26:52
Rasiel
2009-10-09 22:06:49
Make sure you check the generated `model.py` carefully! In particular lengths of `CharField`s and missing `ForeignKey`s was the problem cases last time I used it. It saved many hours of making the `model.py` by hand though.
Nick Craig-Wood
2009-10-10 13:34:58
Django continues to amaze!
T. Stone
2009-10-11 07:31:03