On Tue, 20 Sep 2011 09:14:20 -0400
Michael Bayer <[email protected]> wrote:
>
> On Sep 20, 2011, at 3:24 AM, Enrico Morelli wrote:
>
> > Dear all,
> >
> > I'm using SA 0.6.7 on a RHEL 6 with Python 2.6 and PostgreSQL 8.4.7.
> > These are some table of my DB:
> > pdb_table = Table('pdb', metadata,
> > Column('id', types.Integer, primary_key=True),
> > Column('code', types.Unicode(4), nullable=False),
> > )
> > chain_table = Table('chain', metadata,
> > Column('id', types.Integer, primary_key=True),
> > Column('letter', types.Unicode(1), nullable=False),
> > Column('pdb_id', types.Integer, ForeignKey('pdb.id')),
> > )
> >
> > metal_table = Table('metal', metadata,
> > Column('id', types.Integer, primary_key=True),
> > Column('number', types.Integer, nullable=False),
> > Column('name', types.Unicode(4), nullable=False),
> > Column('pdb_id', types.Integer, ForeignKey('pdb.id')),
> > )
> >
> > mapper(Pdb, pdb_table)
> > mapper(Chain, chain_table,
> > properties={
> > 'pdb': relationship(Pdb, backref='chain')
> > })
> > mapper(Metal, metal_table,
> > properties={
> > 'pdb': relationship(Pdb, backref='metal'),
> > 'chain': relationship(Chain, backref='metal'),
> > })
> >
> > If I try to remove a pdb table row related with others from
> > pgAdminIII, I correctly receive the constraint error and the row
> > isn't removed.
> >
> > Using the following code, SA remove all rows related with others
> > without error:
> > for code in open(pdblist):
> > pdb = Session.query(Pdb).filter(Pdb.code==code.strip()).all()
> > for p in pdb:
> > # Remove PDB
> > Session.delete(p)
> > Session.commit()
> >
> > Where I wrong?
>
> Turn on echo=True in your create_engine() and you'll likely see
> SQLAlchemy setting those foreign key columns to NULL. Set them
> to "NOT NULL" to see a nullable constraint error, or add
> "passive_deletes='all'" to each relationship() to turn off the null
> set.
>
> http://www.sqlalchemy.org/docs/orm/relationships.html?highlight=relationship#sqlalchemy.orm.relationship
>
>
Thanks, I tried to put passive_deletes='all' in the relationships:
mapper(Site, site_table,
properties={
'pdb': relationship(Pdb, backref='site', passive_deletes='all'), })
mapper(Chain, chain_table,
properties={
'pdb': relationship(Pdb, backref='chain', passive_deletes='all')
})
But I obtain:
/py_virt/metalweb/lib/python2.6/site-packages/SQLAlchemy-0.6.8-py2.6.egg/sqlalchemy/orm/properties.py:901:
SAWarning: On Chain.pdb, 'passive_deletes' is normally configured on
one-to-many, one-to-one, many-to-many relationships only.
self._determine_direction()
/py_virt/metalweb/lib/python2.6/site-packages/SQLAlchemy-0.6.8-py2.6.egg/sqlalchemy/orm/properties.py:901:
SAWarning: On Site.pdb, 'passive_deletes' is normally configured on
one-to-many, one-to-one, many-to-many relationships only.
self._determine_direction()
--
-------------------------------------------------------------------
(o_
(o_ //\ Coltivate Linux che tanto Windows si pianta da solo.
(/)_ V_/_
+------------------------------------------------------------------+
| ENRICO MORELLI | email: [email protected] |
| * * * * | phone: +39 055 4574269 |
| University of Florence | fax : +39 055 4574253 |
| CERM - via Sacconi, 6 - 50019 Sesto Fiorentino (FI) - ITALY |
+------------------------------------------------------------------+
--
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.