开发者

django - Automate creation of models.py file?

开发者 https://www.devze.com 2023-03-26 13:03 出处:网络
Is there a way to automatically create the model开发者_如何转开发s.py model definition when you already have an existing database?

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:

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号