On Sep 21, 2008, at 9:09 PM, Doug Farrell wrote:

>
> Hi everyone,
>
> I'm new to SqlAlchemy, but I've got some things working and really am
> enjoying it. Right now I'm trying to ORM map some existing MySQL
> database tables to a class. I've read the documentation, I guess I'm
> just not getting it. Can someone help me out. I've done this:
>
> # initialize the sqlite engine and SqlAlchemy base objects
> engine = create_engine('mysql://username:@hostname/database',  
> echo=True)
> meta = MetaData(engine)
>
> myTable = Table('mytable', meta, autoload=True)
> l = [c.name for c in pressrouting.columns]
> print l
>
> And this works fine, but if I try this:
>
> # initialize the sqlite engine and SqlAlchemy base objects
> engine = create_engine('mysql://username:@hostname/database',  
> echo=True)
> meta = MetaData(engine)
> Base = declarative_base(metadata=meta)
>
> class MyTable(Base):
>    __tablename__ = "mytable"
>    Pass
>
> I get this error:
>
> sqlalchemy.exc.ArgumentError: Mapper Mapper|MyTable|mytable could not
> assemble any primary key columns for mapped table 'mytable'
>
> What is this error message trying to tell me?

the "autoload=True" part is missing from your second recipe, so the  
table has no columns and therefore no primary key either.  Add in  
__table_args__ = {'autoload':True}.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to