On Nov 13, 2008, at 8:44 AM, ershadul.hoque wrote:
>
> 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'
this usually suggests you are assigning an integer value to an
attribute which is mapped as an object reference. In this case I'd
ensure that "country_id" is actually the key you used, and that it's
not mapped as a relation().
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---