In order to guide me in stripping down this code to produce an example for positing, are there any options / flags / introspections I can turn on to understand how sql makes decisions about the order in which is writes statements to the DB?
On Friday, September 14, 2018 at 10:13:45 AM UTC-4, Simon King wrote: > > In that case can you show us the code that is causing the problem? > On Fri, Sep 14, 2018 at 2:55 PM Alex Rothberg <agrot...@gmail.com > <javascript:>> wrote: > > > > I am not generating any IDs myself and I already have relationships > between the models. > > > > On Friday, September 14, 2018 at 4:33:08 AM UTC-4, Simon King wrote: > >> > >> On Thu, Sep 13, 2018 at 10:50 PM Alex Rothberg <agrot...@gmail.com> > wrote: > >> > > >> > Is it possible to hint at sqla the order in which it should write out > changes to the DB? > >> > > >> > I am having issues in which I add two new objects to a session, a and > b where a depends on b, but sqla is flushing a before b leading to an fk > issue. I can solve this a few ways: explicitly calling flush after adding > b, or changing the fk constraint to be initially deferred. Ideally I would > not have to do either of these. > >> > > >> > >> If you have configured a relationship between the two classes > >> ( > http://docs.sqlalchemy.org/en/latest/orm/tutorial.html#building-a-relationship), > > > >> and you've linked the objects together using that relationship (a.b = > >> b), then SQLAlchemy will flush them in the correct order. If you are > >> generating your IDs in Python and assigning them to the primary and > >> foreign key columns directly, SQLAlchemy probably won't understand the > >> dependency. > >> > >> Does using a relationship fix your problem? > >> > >> Simon > > > > -- > > SQLAlchemy - > > The Python SQL Toolkit and Object Relational Mapper > > > > http://www.sqlalchemy.org/ > > > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > > --- > > 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 sqlalchemy+...@googlegroups.com <javascript:>. > > To post to this group, send email to sqlal...@googlegroups.com > <javascript:>. > > Visit this group at https://groups.google.com/group/sqlalchemy. > > For more options, visit https://groups.google.com/d/optout. > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.