4 ms·
Why having no schema in your ORM is a good thing? I can understand that having dynamic schema on your DB probably will enable you to quickly change columns, ind
by liuliu 16y ago
Why having no schema in your ORM is a good thing? I can understand that having dynamic schema on your DB probably will enable you to quickly change columns, indexes and so forth. And I understand that having an object that you can plug whatever properties to it at run-time is convenient for programming too. But why you should have no schema for ORM? It seems to me that if you can enforce schema in ORM, you can add columns/indexes as fast as your DB supports too (i.e. change the schema deceleration in your code), and have fewer bugs. Just curious about the reasoning behind this, I cannot figure it out. (Disclaimer: I am not familiar with Python)
- smlacy 16y agoWell, it depends on your application requirements. And, remember that MongoDB itself is schemaless, so any schema validation must happen at the application layer, and thus, is always going to be "soft". For example, just because you declare a field to be an Integer in your application layer, it doesn't mean it's actually going to be an integer when you read an object. (Especially if objects are coming in through other external data sources.) One great use case for schema-less design would be a User object where you wanted to store arbitrary credentials and external profiles from sites like Facebook, Twitter, etc. If you were using an enforced Schema, then you have to re-create the schema from all the external sites you're using, and every time there's a change in any one of those sites you need to "upgrade" your database to include these new fields. It's really pain.