On Dec 1, 12:36 pm, Mike Toews <[email protected]> wrote: > Hi, > > I'm new to Pylons, and I would like to use it with an existing > PostgreSQL database. I understand that SQLAlchemy can set up a > complete database (using "metadata.create_all()"), complete with > foreign keys and sequences, but I have absolutely no interest in this, > since I have already crafted the database using conventional tools, > and Pylons would be simply one of many client apps.
This is how I'm using Pylons and SQLAlchemy (except with both Oracle and Postgres). > So, where do I start to use my existing database with Pylons? I > understand I need something like a model.py file, as explained in > Chapter 7 of the Pylons Book. Do I have to reverse engineer the > tables, sequences, field names/types/constraints, and relations? This > sounds awful. Are there any tools to help me import or translate a > database schema to a Python/SQLAlchemy model? There's the autoload feature (which I ended up not using). There's also a third party tool for generating SQLAlchemy code... can't think of what it's called right now. I've found that doing it by hand isn't really all that bad, especially if you develop your app iteratively and don't try to add the tables at once (auto-complete helps here). I've been building up a library of SQLAlchemy table defs over the last year or so, and the column & FK defs, etc, haven't changed much, if at all, in that time. So, it may seem a bit tedious up front, but I really haven't spent that much time on it. > With the Python model, > can I choose to only define the names and types, and not define > defaults and constraints (since they are already done within the > database)? I think it depends on what you want to do with the model. For example, you could define a table in SQLAlchemy that only knows about one column in your DB, if for some reason your app only cared about that one column. Hope that helps. -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
