DBSession.flush() after the DBSession.add call might be enough.
On Mon, Nov 21, 2011 at 12:48 PM, sajuptpm <sajup...@gmail.com> wrote: > Model > ======== > class VDCTemplates(DeclarativeBase): > __tablename__='cd_vdc_templates' > id = Column(Unicode(50), primary_key=True) > vdc_id=Column(Unicode(50), ForeignKey('cd_vdc.id', > ondelete="CASCADE")) > template_id=Column(Unicode(50), > ForeignKey('cd_account_templates.id', ondelete="CASCADE")) > account_id=Column(Unicode(50), ForeignKey('cd_accounts.id', > ondelete="CASCADE")) > > > code > ====== > acc_template=self.create_template_data() > DBSession.add(acc_template) > > vdc_template = VDCTemplates() > vdc_template.account_id = account_id > vdc_template.vdc_id = vdc_id > vdc_template.template_id = acc_template.id > DBSession.add(vdc_template) > > > > > * Getting IntegrityError error > (IntegrityError) (1452, 'Cannot add or update a child row: a foreign > key constraint fails (`my_cms_ee/cd_vdc_templates`, CONSTRAINT > `cd_vdc_templates_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES > `cd_account_templates` (`id`) ON DELETE CASCADE)') u'INSERT INTO > cd_vdc_templates (id, vdc_id, template_id, account_id) VALUES (%s, %s, > %s, %s)' ['6ae8e571-ebce-6977-150d-09f7127acb5b', 'ab977753- > de54-6e3b-3d7c-644d12f66d63', '8e0ce099-4ba7-2e01-304c-edc18803fbce', > 'b56bc9e3-288b-a98f-a974-b67f90970122'] > > * Its working, if i put transaction.commit() after > DBSession.add(acc_template), but that not atomic. > > * Have any way to make it atomic ??? > > -- > 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. > > -- 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.