I have an object that has a foreign key to another, declared like
@declared_attr
def object_uuid(cls):
return Column(UUID, ForeignKey('object.uuid'), nullable=False)
I then do something like
DBSession.add(object)
DBSession.add(dependent_object)
Where DBSession is declared as
DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension
()))
I then get an error
sqlalchemy.exc.IntegrityError: (IntegrityError) insert or update on table
"dependent_object" violates foreign key constraint...
Am I doing it incorrectly? I think the order of DBSession.add is incorrect,
where I'm adding the main object first then the one with a foreign key to it.
Do I need to somehow commit the first object to the database before the second
one can see it and satisfy the constraint? Ideally it wouldn't be necessary so
that there's not an extra trip to the database.
(Might be relevant but I hadn't worked on this project in about 6-8 months and
I could have sworn this was working fine then. Today when I pulled down the
dependencies from pip I wonder if some version of something that's newer might
be causing the change.)
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.