Re: [sqlalchemy] reflection fails on table with name in all caps

2016-03-14 Thread Alex Hall
That worked! Thank you so much for your patience. Part of it was the code, and part of it turned out to be that I was still using vendorTable = base.classes.VENDR It didn't occur to me that my VENDR class had taken over that part, so base.classes would no longer contain VENDR. When I saw your asse

Re: [sqlalchemy] reflection fails on table with name in all caps

2016-03-14 Thread Mike Bayer
metadata.reflect(..., extend_existing=True), here's a complete example from sqlalchemy import create_engine e = create_engine("mssql+pyodbc://scott:tiger@ms_2008", echo=True) with e.begin() as conn: conn.execute(""" if not exists (select * from sysobjects where name='sometable' an

Re: [sqlalchemy] reflection fails on table with name in all caps

2016-03-14 Thread Alex Hall
I hate to say it, but... AttributeError: VENDR. I've moved different lines all around, above and below the class definition, but nothing I've tried works. The only change was when I put my declaration of base below the class, and Python naturally said it didn't know what my table class was inheriti

Re: [sqlalchemy] reflection fails on table with name in all caps

2016-03-14 Thread Mike Bayer
oh. try it like this: class VENDR(base): __tablename__ = "VENDR" PVVNNO = sqlalchemy.Column(sqlalchemy.String, primary_key=True) __table_args__ = {"extend_existing": True} that tells reflection to add new data to this Table object even though it already exists. On 03/14/2016 09:24

Re: [sqlalchemy] reflection fails on table with name in all caps

2016-03-14 Thread Alex Hall
Thanks for that. Somehow, I'm getting the same error as before--the VENDR table isn't being reflected. Here's the entire snippet, from engine to trying to get the table. engine = sqlalchemy.create_engine("mssql+pyodbc://%s:%s@%s" %(username, password, dsn)) session = Session(engine) metadata = sql

Re: [sqlalchemy] reflection fails on table with name in all caps

2016-03-11 Thread Mike Bayer
like this: class VENDR(MyAutomapBase): __tablename__ = 'VENDR' id = Column(Integer, primary_key=True) Above, the 'id' column name should match the column in the table that you'd like to consider as the primary key (and so should the type) - the "id" / "Integer" combination above is ju

Re: [sqlalchemy] reflection fails on table with name in all caps

2016-03-11 Thread Alex Hall
Sorry, do you mean the base subclass, or a new table class? In either case, I'm not sure I see how this will fit into my automapping code. I know this is all fairly basic, I just can't quite picture what goes where and what inherits from/gets passed to what to make it automap this VENDR table. If I

Re: [sqlalchemy] reflection fails on table with name in all caps

2016-03-11 Thread Mike Bayer
just make the class and include the PK column, then automap. the rest of the columns should be filled in. On 03/11/2016 04:14 PM, Alex Hall wrote: Ah, you're right. Every other table I've used in this database has had a key, and I didn't even notice that this VENDR table lacks one. That expla

Re: [sqlalchemy] reflection fails on table with name in all caps

2016-03-11 Thread Alex Hall
Ah, you're right. Every other table I've used in this database has had a key, and I didn't even notice that this VENDR table lacks one. That explains the mystery! Thanks. Now to map this table. I've read the section of the docs on doing this, and I get that I subclass base, set __table__ to be my

Re: [sqlalchemy] reflection fails on table with name in all caps

2016-03-11 Thread Mike Bayer
ah. does VENDR have a primary key? it won't be mapped if not. what's in base.classes.keys() ? base.classes['VENDR'] ? On 03/11/2016 12:47 PM, Alex Hall wrote: VENDR is right there, in base.classes and metadata.tables. Yet, vendorTable = base.classes.VENDR raises an AttributeError. Odd

Re: [sqlalchemy] reflection fails on table with name in all caps

2016-03-11 Thread Alex Hall
VENDR is right there, in base.classes and metadata.tables. Yet, vendorTable = base.classes.VENDR raises an AttributeError. Odd! There's nothing cap-sensitive about __hasattr__ that I'm forgetting, is there? Or, could I somehow alias the name before I try to access it, if that would help at all? Thi

Re: [sqlalchemy] reflection fails on table with name in all caps

2016-03-11 Thread Mike Bayer
can you look in metadata.tables to see what it actually reflected ? On 03/11/2016 12:09 PM, Alex Hall wrote: That's weird: the name I see is exactly what I've been using, "VENDR". All caps and everything. I tried using lowercase, just to see what it would do, but it failed. On 3/11/16, Mi

Re: [sqlalchemy] reflection fails on table with name in all caps

2016-03-11 Thread Mike Bayer
On 03/11/2016 09:39 AM, Alex Hall wrote: Hello list, Finally, a pure SA question from me. I'm using Automap and the "only" keyword to automap a subset of the tables in our CMS database. This has worked perfectly thus far. Now, though, it's failing on a specific table, and the only difference I

Re: [sqlalchemy] reflection fails on table with name in all caps

2016-03-11 Thread Alex Hall
That's weird: the name I see is exactly what I've been using, "VENDR". All caps and everything. I tried using lowercase, just to see what it would do, but it failed. On 3/11/16, Mike Bayer wrote: > > > On 03/11/2016 09:39 AM, Alex Hall wrote: >> Hello list, >> Finally, a pure SA question from me.

[sqlalchemy] reflection fails on table with name in all caps

2016-03-11 Thread Alex Hall
Hello list, Finally, a pure SA question from me. I'm using Automap and the "only" keyword to automap a subset of the tables in our CMS database. This has worked perfectly thus far. Now, though, it's failing on a specific table, and the only difference I can see is that this table's name is in all c