Michael Bayer wrote:

>On Feb 16, 2007, at 3:46 PM, jose wrote:
>  
>
>>No Jonathan, I don't want this column is set as NOT NULL, I have to
>>allow null values for this column and I don't want enable the "ON  
>>DELETE
>>SET NULL" functionality.
>>I would like SA have the same behavior as PostgreSQL has, I like the
>>message:
>>
>>pg> delete from specie where codice='89';
>>ERROR:  update or delete on "specie" violates foreign key constraint
>>"attivita_cod_specie_fkey" on "attivita"
>>DETAIL:  Key (codice)=(89) is still referenced from table "attivita".
>>
>>Is there another way to do that?
>>    
>>
>
>
>basically, if you have A->B, and you delete "A" without any kind of  
>"delete" cascade to "B",  you are basically telling SA, "delete "A"  
>from the database and keep "B"".   SA appropriately is smart enough  
>to know that it should break the relationship from A to B before  
>deleting A.
>  
>

>if that operation violates an integrity constraint in your  
>application then youd have a NOT NULL constraint sitting on "B"'s  
>foreign key to A.  That you say you dont want the "NOT NULL" on the  
>column is a little strange...I dont exactly understand an  
>"occasional" not-null constraint on a foreign key column.
>  
>
In a perfect world, we will not need NULLs, but for the moment it is 
better to be realistic,
we don't have an answer for any question and sometimes we have to 
respond "I DON'T KNOW" and this transalted to SQL as NULL.
This is why we have LEFT/RIGTH JOINs in SQL.
In my case I need a foreign key that sometimes haven't a value.

Anyway, I think I need to wonderstand better how backrefs works, seems 
to me that SA activate the ON DELETE SET NULL
when there's a backref in the relation.

My definition was:

assign_mapper(context, Attivita, tbl['attivita'], properties = dict(specie = 
relation(Specie, backref='attivita'))

now it is:

assign_mapper(context, Attivita, tbl['attivita'], properties = 
dict(specie = relation(Specie))
and it works as I want. :-)

jo

>you might find setting "delete-orphan" cascade on the relationship  
>might raise an error for "B" sitting in the session by itself,  
>though.  but then you cant save any "B"s by themselves.
>
>
>
>
>>
>  
>


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