maybe try uselist=True in both relation and backref ?? 
just guessing

On Wednesday 25 June 2008 11:36:02 [EMAIL PROTECTED] wrote:
> Hi.
>
> I'm trying to insert new data into db using one-to-one
> relationship, but i'm getting this error:
> "sqlalchemy.exceptions.OperationalError: (OperationalError) (1048,
> "Column 'address_id' cannot be null") u'INSERT INTO companies
> (address_id, company, ico, dic, bank_account) VALUES (%s, %s, %s,
> %s, %s)' [None, u'Vnet a.s.', u'2332521351', u'SK234623513',
> u'132412153/0900']"
>
> Here is the code:
> class Address(Template):
>     pass
> class Client(Template):
>     pass
>
> addresses =         Table('addresses', metadata, autoload=True)
> clients =           Table('clients', metadata,
>                         Column('address_id', Integer,
> ForeignKey('addresses.id')),
>                         autoload=True)
>
> orm.mapper(Client, clients, properties={
>             'address': orm.relation(Address,
> backref=backref('client', uselist=False)) })
>
> ses = SQLSession()
> client = Client(**client_data)
> address = Address(**address_data)
> client.address = address
> ses.save(client)
> ses.commit()
> ses.close()
>
> The problem is, that sqlalchemy does not set the 'address_id'
> column in 'clients' table.
> How is the sqlalchemy-way to do this??
>
> I was able to do it this way:
> ses.SQLSession()
> client = Client(address_id=0, **client_data)
> ses.save(client)
> ses.commit()
> ses.rollback()
> client.address = b.Address(**address_data)
> ses.commit()
> ses.close()
>
> Thanks
> Pavel
>
> 


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to