> -----Original Message----- > From: sqlalchemy@googlegroups.com > [mailto:sqlalch...@googlegroups.com] On Behalf Of Gaicitadie > Sent: 16 April 2010 20:06 > To: sqlalchemy > Subject: [sqlalchemy] Is the mapper must have a primary_key? > > #!/usr/bin/python > # -*- coding: UTF-8 -*- > > from sqlalchemy import * > from sqlalchemy.orm import * > from sqlalchemy.ext.declarative import declarative_base > > Base = declarative_base() > > class Test(Base): > __tablename__ = 'test' > > tid = Column(Integer) > > > engine = create_engine('sqlite:///:memory:', echo=True) > metadata = Base.metadata > metadata.create_all(engine) >
[SNIP] > > > It seems must make a primary_key for table,but my table need't > primary_key,what can i do? > The ORM part of SQLALchemy requires that you have some combination of columns that uniquely identify a row in the database. This is so that when you load an instance from the database, then modify it and flush your changes back to the database, the updates actually get applied to the correct row. It also means that if you load rows from the same table more than once in the same Session, you always get the same instance back for a given row. Note that the columns don't have to actually be a primary key in the database. If you are treating the database as read-only and you have rows in your table which really are identical, you may be better off just using the lower-level SQL expression language part of SA, which doesn't have these constraints. Hope that helps, Simon -- 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.