Hello ALL:
i has 2 table.
_Table_Metadata = declarative_base(cls = DictableModel)
class MainTable(_Table_Metadata):
__tablename__ = 'MainTable'
id = Column(BIGINT, primary_key = True, autoincrement = True, unique = True)
number = Column(Text, unique=True, nullable=False)
name = Column(Text, unique=True, nullable = False)
class SubTable(_Table_Metadata):
__tablename__ = 'SubTable'
id = Column(BIGINT, primary_key = True, autoincrement = True, unique = True)
mainkey = Column(ForeignKey(MainTable.number))
number = Column(Text, unique = True, nullable = False)
name = Column(Text, unique = True, nullable = False)
---------------------------------------------------------------------------------
try:
_conn.execute('SAVEPOINT AAA;')
_conn.execute("INSERT INTO MainTable(number, name) VALUES( '00001', '00001'
);")
_conn.execute('RELEASE SAVEPOINT AAA;')
_conn.execute('SAVEPOINT AAA;')
_conn.execute("INSERT INTO SubTable(mainkey, number, name) VALUES('00001',
'00001', '00001');")
_conn.execute('RELEASE SAVEPOINT AAA;')
except:
_conn.execute( 'ROLLBACK' )
else:
_conn.execute("COMMIT")
is OK, 2 Table has record
---------------------------------------------------------------------------------
try:
M1=MainTable()
_conn.begin_nested()
M1.number = '00001'
M1.name = '00001'
_conn.add(M1)
_conn.commit()
M2 = SubTable()
_conn.begin_nested()
M1.mainkey - "00001"
M2.number = '00001'
M2.name = '00001'
_conn.add(M2)
_conn.commit()
except:
_conn.rollback()
else:
_conn.commit()
(psycopg2.IntegrityError) insert or update on table "SubTable" violates
foreign key constraint "SubTable_MainTable_fkey"
DETAIL: Key (mainkey)=(00001) is not present in table "MainTable".
the SA echo add(M2) before has BEGIN (implicit) again, and insert data and
rollback savepoint
-------------------------------------------------------------------------
how can save SubTable?
the example is short,
my project subtable has more table data modify.
so SAVEPOINT is must.
but i can't serach any fix
is add(M2) before again BEGIN (implicit) bug ?
--
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.