The primary keys in my db are GUIDs, char(36).  When I generate the
GUID in python using the uuid module, everything works fine.  But when
I allow the db to generate the GUIDs I get foreign key errors when
trying to save a new parent and child.

A look at the SQL generated shows that the parent is being saved
first, but when the child is saved, it does not have the parent's new
primary key in the related field.  Instead of the parent's new GUID in
the related field, it has 0L.

When using the first method below, what is stopping sqlalchemy from
getting the newly created guid so it can be referenced by the child's
SQL??

# This way does not work
#
-----------------------------------------------------------------------
def colId(): return Column('id', types.CHAR(36), primary_key=True,
        default=func.convert(literal_column('UUID() USING utf8')))

# This way works
#
-----------------------------------------------------------------------
from uuid import uuid4
def colId(): return Column('id', types.CHAR(36), primary_key=True,
        default=lambda: str(uuid4()))

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to