Chapter 10.2.4. Automatic Table Description from Existing DB Schema

This is the flip-side of automatic DB schema creation. If you already have an existing database, you don’t have to labor through defining every column as an attribute of your model classes. You can just specify _fromDatabase = True and be done with it. Here is how it’s done:

class FighterRobot(SQLObject):
    _fromDatabase = True

Note

This system only works if the database itself and the Python drivers for that database provide the introspection capabilities that SQLObject needs. For example, this doesn’t work for SQLite right now, but MySQL and Postgres work just fine. If you use one of the less commonly used SQLObject backends, your experience may vary.

Remember that your ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.