Database first Django models

血红的双手。 提交于 2021-01-27 06:05:30

问题


In ASP.NET there is entity framework or something called code first from database. Is there something similar for Django? I usually work with a pre-existing database that I need to create a backend (and subsequently a front end) for. Some of these RDBs have many tables and relations so manually writing models isn't a good idea. I've scoured Google for solutions but have come up relatively empty handed. Thoughts would be appreciated.

Thanks!


回答1:


You can use the information on this link.

python manage.py inspectdb > models.py

https://docs.djangoproject.com/en/3.0/howto/legacy-databases/ It depends on your database, but I've worked with it and is good.




回答2:


The default in Django is a Code First-type approach where the Django framework engine creates a Db for you based on your models and uses migrations to update the Db with model changes (like Code First). https://docs.djangoproject.com/en/1.11/intro/tutorial02/

What you're describing sounds like a Database First approach in the .Net world. Integrating Django with a legacy database: https://docs.djangoproject.com/en/1.11/howto/legacy-databases/



来源:https://stackoverflow.com/questions/30519149/database-first-django-models

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!