Gary Bernhardt wrote:

> Referential integrity isn't being violated here - SA is nulling the 
> foreign key before deleting the row it points to.  Try adding 
> nullable=False to the declaration of attivita.cod_specie.  That should 
> make it fail in the way you expect, because SA will no longer be able 
> to null the foreign key.

This seems to me a trick to avoid integrity referential.
I expected the nullable=False was the default behavior for any foreign 
key otherwise the referential integrity is violated here?
I'm very, very surprised for this behavior.
Anyway, I'm  using autoload to define my tables thus I don't know how to 
add nullable=False to my tables.

jo


>
> On 2/16/07, *Jose Soares* <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
>
>
>     Hi all,
>
>     I wonder how SA could delete a row of my table (postgresql) linked
>     with
>     another table.
>     Take a look...
>
>     pg=> select * from attivita where cod_specie='33';
>     codice |                     descrizione                      |
>     cod_specie
>     
> --------+-----------------------------------------------------+------------
>     21311  | Sezionamento selvaggina allevata                     | 33
>
>     pg=> select * from specie where codice='33';
>
>     codice | descrizione
>     -------+-------------
>     33     | Selvaggina
>     (1 row)
>
>     sfera=> delete from specie where codice='33';
>     ERROR:  update or delete on "specie" violates foreign key constraint
>     "attivita_cod_specie_fkey" on "attivita"
>     DETAIL:  Key (codice)=(33) is still referenced from table "attivita".
>
>     --------------------------
>     let's try now using SA:
>
>     tg-admin shell
>
>     In [1] aa=Specie.get_by(codice='33')
>
>     In [3]: aa.delete
>     Out[3]: <bound method Specie.do of <Specie 33>>
>
>     In [4]: aa.delete()
>
>     In [5]: aa.flush()
>     2007-02-16 15:30:31,955 sqlalchemy.engine.base.Engine.0x..f4 INFO
>     BEGIN
>     2007-02-16 15:30:31,958 sqlalchemy.engine.base.Engine.0x..f4 INFO
>     SELECT
>     attivita.cod_specie AS attivita_cod_specie, attivita.attivo AS
>     attivita_attivo, attivita.cod_attivita_istat AS
>     attivita_cod_attivita_istat, attivita.descrizione AS
>     attivita_descrizione, attivita.cod_prodotto AS attivita_cod_prodotto,
>     attivita.cod_tipologia_struttura AS attivita_cod_tipologia_s_2e27,
>     attivita.cod_organizzazione AS attivita_cod_organizzazione,
>     attivita.cod_orientamento_produttivo AS attivita_cod_orientament_583a,
>     attivita.codice AS attivita_codice
>     FROM attivita
>     WHERE %(lazy_b4ba)s = attivita.cod_specie ORDER BY attivita.codice
>     2007-02-16 15:30:31,958 sqlalchemy.engine.base.Engine.0x..f4 INFO
>     {'lazy_b4ba': '33'}
>     2007-02-16 15:30:31,979 sqlalchemy.engine.base.Engine.0x..f4 INFO
>     UPDATE
>     attivita SET cod_specie=%(cod_specie)s WHERE attivita.codice =
>     %(attivita_codice)s
>     2007-02-16 15:30:31,980 sqlalchemy.engine.base.Engine.0x..f4 INFO
>     {'cod_specie': None, 'attivita_codice': '01302'}
>     2007-02-16 15:30:31,986 sqlalchemy.engine.base.Engine.0x..f4 INFO
>     DELETE
>     FROM specie WHERE specie.codice = %(codice)s
>     2007-02-16 15:30:31,986 sqlalchemy.engine.base.Engine.0x..f4 INFO
>     {'codice': '33'}
>     2007-02-16 15:30:31,990 sqlalchemy.engine.base.Engine.0x..f4 INFO
>     COMMIT
>
>
>     pg=> select * from specie where codice='33';
>
>     codice | descrizione
>     -------+-------------
>     pg=> select * from specie where codice='33';
>
>     codice | descrizione
>     -------+-------------
>     (0 row)
>
>
>
>     >


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