简体   繁体   English

数据库优先 Django 模型

[英]Database first Django models

In ASP.NET there is entity framework or something called code first from database.在 ASP.NET 中,有实体框架或称为数据库优先代码的东西。 Is there something similar for Django? 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.其中一些 RDB 有许多表和关系,因此手动编写模型不是一个好主意。 I've scoured Google for solutions but have come up relatively empty handed.我已经在谷歌上搜索了解决方案,但相对而言却是两手空空。 Thoughts would be appreciated.想法将不胜感激。

Thanks!谢谢!

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. https://docs.djangoproject.com/en/3.0/howto/legacy-databases/这取决于您的数据库,但我已经使用过它并且很好。

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). Django 中的默认值是 Code First 类型的方法,其中 Django 框架引擎根据您的模型为您创建一个 Db,并使用迁移来更新具有模型更改的 Db(如 Code First)。 https://docs.djangoproject.com/en/1.11/intro/tutorial02/ https://docs.djangoproject.com/en/1.11/intro/tutorial02/

What you're describing sounds like a Database First approach in the .Net world.您所描述的听起来像是 .Net 世界中的数据库优先方法。 Integrating Django with a legacy database: https://docs.djangoproject.com/en/1.11/howto/legacy-databases/将 Django 与旧数据库集成: https : //docs.djangoproject.com/en/1.11/howto/legacy-databases/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM