Suppose I have two tables in mysql, there is no referential constraint
defined.
Tables: banks, locations
Schema for banks: id, name, country_id
Schema for locations: id, name

banks.country_id will be foreign key of locations.id, but
banks.country_id can be null too.


Two tables are reflected as follows:

Class Bank(object):
    pass
class Location(object):
    pass

there were load as follows:

bank_table = Table('banks',metadata, autoload = True)
location_table = Table('locations',metadata, autoload = True)

mapper(Location, location_table)
mapper(Bank, bank_table, properties =
              {'country': relation(Location,
                                   primaryjoin =
bank_table.c.country_id == location_table.c.id,
                                   foreign_keys =
[bank_table.c.country_id],
                                   lazy = False,
                                   uselist = False
                                   )
              }
              )
Now i was going to add a bank object , using the following data
{'name': 'Bank A', 'country_id': '1'}
I was called by the following error:
exception = 'int' object has no attribute '_sa_instance_state'

please help me.

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