On Thu, May 20, 2010 at 8:09 PM, Michael Bayer <[email protected]> wrote: > > On May 20, 2010, at 5:51 PM, Yang Zhang wrote: > >> How do I create an ORM type with no primary key columns? For some >> reason I'm getting: >> >> sqlalchemy.exc.ArgumentError: Mapper >> Mapper|ActorActivity|actor_activities could not assemble any primary >> key columns for mapped table 'actor_activities' >> >> for: >> >> class ActorActivity(Base): >> __tablename__ = 'actor_activities' >> actor_id = Column(UUID, ForeignKey(Actor.id), nullable = >> False) >> t = Column(SmallInteger, nullable = False) >> ts = Column(TIMESTAMP, nullable = False) >> a = Column(UUID, ForeignKey(A.id)) >> b = Column(UUID, ForeignKey(B.id)) >> n = Column(SmallInteger) >> x = Column(SmallInteger) >> >> Thanks for any hints. > > > the orm has to be given the list of columns that serve as the primary key > even if the table doesn't actually have any. FAQ entry here: > http://www.sqlalchemy.org/trac/wiki/FAQ#IhaveaschemawheremytabledoesnthaveaprimarykeycanSAsORMhandleit
I did see that, and the only thing I'll say here is: I know what I'm doing :) > > although here you can just put "primary_key=True" on those columns you'd like > to consider as PK cols, since you are using declarative and everything is in > one place anyway. > > if the issue is, you want no PK at all, even a python-only one, that's not > really possible. The ORM needs a way to locate the row for your instance in > the DB in order to issue updates/deletes etc. Thanks for the anwser. It would be nice if this restriction could be lifted if explicitly requested somehow (__use_pk__ = False, and have those operations raise run-time exceptions if attempted). (As for why I'm using the ORM, it's basically because it affords many relatively minor benefits such as packaging up the tuple in its own object, a cleaner declaration syntax than Table(...), no need to use table.c.blah, custom constructors and methods, etc.) -- Yang Zhang http://yz.mit.edu/ -- 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.
