Hi All,

Can someone tell me why this script:

from datetime import datetime
from sqlalchemy import create_engine, Table, Column, Integer, String, 
DateTime, ForeignKey
from sqlalchemy.orm import sessionmaker, relation, backref
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine('sqlite://')
Base = declarative_base(engine=engine)

class Unit(Base):
     __tablename__ = 'units'
     id = Column(Integer,primary_key=True)
     name = Column(String)

class Record(Base):
     __tablename__ = 'records'
     timestamp = Column(DateTime,primary_key=True)
     unit_id = Column(Integer,ForeignKey('units.id'),primary_key=True)
     unit = relation('Unit',
                     backref=backref('records',order_by=timestamp))

Base.metadata.create_all()

session = sessionmaker(bind=engine)()
unit = Unit(id=1,name='unit 1')
session.merge(unit)
session.add(Record(
             timestamp = datetime.now(),
             unit = unit,
             ))
session.merge(Unit(id=2,name='unit 2'))

...barfs on the second session.merge with an eexception that ends as 
follows:

sqlalchemy.exc.IntegrityError: (IntegrityError) PRIMARY KEY must be 
unique u'INSERT INTO units (id, name) VALUES (?, ?)' [1, 'unit 1']

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk

--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to