Reading this blog post, Why schema definition belongs in the database I fully agree what the author said. Pretty much what I’m thinking lately about the state of ORM in python world. Look’s like everyone trying to shoot off SQL and be it all python. Just look into the django, one of the major drawback which keep me away from it is the model where you have to specify in Python. I love python either but that does not mean everything should be in python. I’ve spent a lot of time learning sql and now I have to learn again how to define it in python. That’s still ok but what I really don’t like is the redundant definition of your schema. Your database schema is well defined within the SQL so there’s no point to redefine it again in your model. Python crowd would argue that “Explicit is better that implicit” but IMO, this does not apply to SQL.
Back to the days when I’d involved in writing ORM in PHP, one of our goal is to reduce the probability of introducing error in the various layer of the application. Sort of error such as validating form field to not exceed than 5 while in db it suppose to be 4 and other bugs relating miss match between the application and db. So one of the ORM goal is to pull everything from the db. The db is your application. Everything is well defined there and if you make any changes it will reflected to the whole application. Changing column lenght in db would update the column attributes in model and also change the form size together with it’s validation rule. The models, most of the time would only contain a reference to the db table and probably some validation method.
class Node extends db_table {
table_name = 'Node'
function validate() {
//your validation logic
}
}
Most of the ORM tools in Python except django models support certain degree of introspection into db. For example, in sqlobject if you do not want to define the model in python:-
class Node(sqlobject):
class sqlmeta:
fromDB = True
SQLAlchemy also provide introspection into the db and based on first glance through the documentation look’s much better and native compared to sqlobject which I guess preferred to define the model in python. IMO, defining the model in your code just introduce another problem. Now you have to maintain the definition in two place. Every time you changed the db, you have to go through all the models and change it as well. It’s not too hard if you only have a few tables but if it count to hundred or more, you can guess it. I’ve gone through this before.
However, it’s look’s like most of the python major frameworks such as django and turbogear preferred to define the models in python rather than pulling it directly from database.

Comments
yes, schema definition belongs to database
Just blog that link 'Why schema definition belongs in the database',
where-should-define-database-schema
Should read yours first :)