Mark wrote:
> sqlalchemy.exc.ArgumentError: Mapper Mapper|Admin|admin could not
> assemble any primary key columns for mapped table 'admin'
>
> As you can see above, I have already mapped the primary_key=True
> property, why is it still complaining that it can't find the primary
> key?  With this error, I tried out something else, adding the code
> below to my mapper configuration:
>
> primary_key=[TABLES.ADMIN_TABLE.columns.username]
>
> Adding this, allowed me to run the server properly, however, when I
> query the database, it claims that it is unable to locate the username
> column.  I am very sure my database is correct and this is definitely
> an issue with my SQLAlchemy code.
>

here is a script that imitates the patterns you are using, and it runs
fine, both for the reflected/overridden primary key column, as well as the
manual mapping of pk column.   Assuming this script works fine for you,
you'd need to identify what is different about your
application/environment versus this test script.

from sqlalchemy import *
from sqlalchemy.orm import *

engine = create_engine('sqlite://', echo=True)

# note no pk in the table
engine.execute("create table foo (id integer, bar integer)")
engine.execute("insert into foo (id, bar) values (?, ?)", [(1, 1), (2, 5),
(3, 7)])

m = MetaData(engine)
table = Table('foo', m,
    Column("id", Integer, primary_key=True),
    autoload=True
)

assert list(table.primary_key) == [table.c.id]

class Foo(object):
    pass

mapper(Foo, table)

print create_session().query(Foo).all()

clear_mappers()

mapper(Foo, table, primary_key=[table.c.id])

print create_session().query(Foo).all()




-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to