Hi all,
I have begun using SQLAlchemy in earnest for a database project I've
begun, and I am running into some roadblocks with inserts of very
simple objects.
I have generated a very simple class to represent an entity called a
Project:
class Project(object):
def __init__(self, project):
self.project = project
def __repr__(self):
return "<Project('%s')>" % (self.project)
I have created a project table defined as follows:
projectTbl = Table('project', meta,
Column('project_id', Integer,
PassiveDefault(''),
primary_key=True),
Column('project', String(100), unique=True,
nullable=False),
Column('crt_date', DateTime,
nullable=False)
)
I created a mapping for the table which looks like this:
projectMap = mapper(Project, projectTbl, properties={
'compounds':relation(Compound, secondary=cpdProjAssoc,
backref='projects')
})
I have created a method to save projects which takes a Project object
as an argument:
def addProject(project):
sess = Session()
try:
sess.save_or_update(project)
except Exception:
sess.rollback()
print 'Error encountered trying to insert project ' +
project.project
else:
sess.commit()
I next create a list of projects, iterate over them, attempting to
save them:
projects = []
projects.append(Project('None'))
projects.append(Project('Proj1'))
projects.append(Project('Proj2'))
projects.append(Project('Proj3'))
for p in projects:
addProject(p)
Unfortunately, when I iterate over the list and attempt to save each
project, I get the following error message:
FlushError: New instance [EMAIL PROTECTED] with identity key (<class
'Project'>, (None,), None) conflicts with persistent instance
[EMAIL PROTECTED]
Is part of my problem the fact that I have a trigger defined in the
database to increment the primary key of the project table? Any idea
what could be at issue here?
Joann
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---