Is there a way to automatically create the model开发者_如何转开发s.py model definition when you already have an existing database? I have a complicated database with tables and relationships already setup up in MySQL, and would like to avoid creating the models.py file from scratch if possible.
You can use :
./manage.py inspectdb > models.py
According to the documentation :
The inspectdb utility introspects the database pointed to by your settings file, determines a Django model representation for each of your tables, and prints the Python model code to standard output.
More information in the Django Book 2.0 - Chapter 18:
精彩评论