Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I design the database for Django?

I like to use a GUI application to design databases using ERD. Currently I am using the EER Diagram of the free MySQLWorkbench.

Once I like the way the ERD looks, I Forward Engineer the ERD in MySQLWorkbench to create the actual database. Then I introspect the MySQL database with django-admin.py inspectdb to Reverse Engineer into an output of a Python snippet code for Django's models.py.

But then I have to take the inspectdb output and manually edit it to my liking. One particular part I really don't like to do is manually eliminating each join table from a many-to-many relationship.

Is there a good (and preferably free) GUI ERD design program out there specifically designed for Django?

like image 482
hobbes3 Avatar asked Dec 22 '22 01:12

hobbes3


1 Answers

If you wish to design your models at the database level, in the way that you're describing, you are going to need to do exactly that: design your SQL and then convert that into Django models.

This is not the normal way of designing a Django application: typically you would design the models as you wanted them to be, and only put a lot of effort into schema design if you need to resolve some performance problems. Django models aren't really meant to be an abstraction of a relational database: they're meant to be an abstraction of your application's persisted objects, which happens to be implemented on top of a relational database.

There is nothing wrong with wanting/needing to do an explicit schema design, but it makes you a bit of an outlier (most web devlelopers don't), hence the difficulty you're having finding tools suited to your needs.

The closest thing is the graph_models command which is part of Django command extensions. This lets you visualize your models (you still write them in python code, but the visual representation will help you iterate faster).

like image 158
kdt Avatar answered Dec 26 '22 00:12

kdt