Darwin's Theories Blog

New Theories for a New Time

Django Reverse-Engineer from Existing Legacy Tables

2008-10-04
I've been playing a bit with Django, a Python-based web framework. One thing that people starting in Django seem to miss out on is the standard "how to I make model classes from my existing database tables"? That's not because you can't do this, but only because most of the newb tutorials start from the other end. It turns out that you can do this easily using "manage.py inspectdb". And you're done, at least most of your work is done. This reverse engineering is not as complete as that in Seam (actually Hibernate) - no compound primary keys, and (presumably because Python's db support is less general than Java's JDBC) it only works on a few databases (PostgreSQL, MySQL and SQL Server, IIRC), but for those database it does the bulk of the work for you.

So, this post is a bit away from my usual topics. I admit it, I'm mainly posting this here in hopes that somebody else using a web search will find the answer more quickly.
Reply from Anonymous at 2009-04-09 03:40:54.763

So, I have to say, that after using search engine (google) I came here :-) Thanks for your info. On django website they really don't do much pressure on this point of view.

Have a nice day!

Reply from Buckyball at 2009-07-01 14:19:27.384

You also helped me out with that, thx 4 writing this down.

Reply from Anonymous at 2011-03-29 10:16:40.993

+1, helped me too - thanks!

Reply from Carlos at 2011-05-18 15:33:10.982

+1
Found it very usefull.

Thanx