简体   繁体   English

Django:从模型生成数据库与数据库的模型

[英]Django: Generate models from database vs database from models

I'm getting myself acquainted with MVC by making a 'for-fun' site in django. 我通过在django制作一个“有趣”的网站,让自己熟悉MVC。 I'm really liking a lot of the features of the api and python itself. 我真的很喜欢api和python本身的很多功能。 But one thing I really didn't like was that django encourages you to let it build your database FOR you. 但我真的不喜欢的一件事是django鼓励你让它为你建立你的数据库。 I'm well aware of inspectDB and I'm interested in using it. 我很清楚inspectDB,我对使用它感兴趣。

So my question is this, is there any solid reason that I should choose one method of model/DB generation over another? 所以我的问题是,有什么可靠的理由我应该选择一种模型/数据库生成方法而不是另一种方法? I feel far more comfortable defining my database in the traditional SQL way (where I have access to combined keys). 我觉得用传统的SQL方式(我可以访问组合键)来定义我的数据库会更加舒服。 But I'm concerned using things that aren't available through the Model api may cause problems for me later on. 但我担心使用Model api无法提供的东西可能会在以后给我带来问题。 Such as combined keys, medium_text, etc. 如组合键,medium_text等

I'm using mysql btw. 我正在使用mysql btw。

If you're starting a new project, always let Django generate the tables. 如果你正在开始一个新项目,总是让Django生成表。 Django provides mechanisms to use a pre-existing database to support legacy data or situations where you aren't in direct control of the database structure. Django提供了使用预先存在的数据库来支持遗留数据或不直接控制数据库结构的情况的机制。 This is a nice feature of Django for those who need it, but it creates more work for the developer and breaks many conventions in Django. 对于那些需要它的人来说,这是Django的一个很好的功能,但它为开发人员创造了更多的工作并打破了Django中的许多约定。

You still can, and in fact are encouraged to, add additional indexes and any other database-specific optimizations available to you after the fact . 您仍然可以,实际上是鼓励,增加额外的指标,并在事后提供给您的任何其他特定数据库的优化。

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

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