I am using SQLAlchemy 0.9 with Python 2.7.6 and Flask.
I receive form data, place it into object and add the objects to the session. When I try to do a db.commit() I get a rollback which seems to due to the relationship object in the INSERT statement. The SQL error is as follows:
INFO sqlalchemy.engine.base.Engine INSERT INTO site (name, address1, address2, postcode, city, fk_country_id, fk_school_id) VALUES (%(name)s, %(address1)s, %(address2)s, %(postcode)s, %(city)s, %(fk_country_id)s, %(fk_school_id)s) RETURNING site.id
INFO sqlalchemy.engine.base.Engine {'city': u'New York', 'fk_school_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x8c274ac>, 'name': u'Site1', 'address1': u'2 York Way', 'address2': u'', 'postcode': u'12345', 'fk_country_id': u'2'}
INFO sqlalchemy.engine.base.Engine ROLLBACK (ProgrammingError) can't adapt type 'InstrumentedAttribute'
The relationship code in the model is as follows:
class Site(db.Model):
id = db.Column(db.Integer, primary_key = True)
school = db.relationship('School', backref = 'site', uselist = False)
What is it about the relationship object that causes the rollback? I am new to SQLAlchemy and so have followed what it says in the documentation regarding relationships.
Both of the data types in the models (Site, School) are ints.