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
> --
> -------------------------------------------------------------------
> (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.
>
--
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.