Stephen, Thanks for the response. I got around the primary key by making explicit sql queries (luckily only a few small tables were problematic.)
Thanks again, -neil On Tue, Apr 28, 2009 at 1:11 AM, Stephen Emslie <[email protected]>wrote: > Hi Neil > > I managed to make queries on those tables by creating a new table > definition and getting a class mapping from that explicitly, for > example: > > > >>> from sqlalchemy.ext.sqlsoup import SqlSoup > >>> from sqlalchemy import * > >>> engine = create_engine('sqlite:///:memory:') > >>> metadata = MetaData(bind=engine) > >>> retailer_table = Table('retailer', metadata, Column('retailer_id', > primary_key=True), autoload=True) > >>> db = SqlSoup(metadata) > >>> Retailer = db.map(retailer_table) > >>> Retailer.first() > > MappedRetailer(retailer_id=33199, ...) > > > So then the Retailer class returns MappedRetailer instances even > though the underlying schema defines no primary key. That part seemed > fine, but I then had to work with relations on those tables that I was > mapping explicitly and I found it easier at that point just to skip > SqlSoup and define the table metadata and mapping myself. > > > I hope that helps. > > Stephen Emslie > > On Sun, Apr 26, 2009 at 11:48 PM, NeilK <[email protected]> wrote: > > Hi Stephen, did you find a way to access those tables without a > > primary key using SqlSoup? > > > > Thanks, > > -neil > > > > On Apr 25, 3:42 am, Stephen Emslie <[email protected]> wrote: > >> I am using SqlSoup to do a little maintenance on a database whose > >> schema I have no control over. Unfortunately some tables are without a > >> primary key, and thus SqlSoup complains when accessing them: > >> > >> sqlalchemy.ext.sqlsoup.PKNotFoundError: table 'category' does not have > >> a primary key defined > >> > >> When reflecting tables directly with sqlalchemy, using Table(name, > >> meta, autoload=True), one can override the reflected columns to > >> compensate for the lack of a primary key. Is this possible in SqlSoup? > >> > >> Stephen Emslie > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" 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/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
