thanks a lot michael.

i think i'll go this way :)

best regards,
alex

On 07/07/2012 05:13 PM, Michael Bayer wrote:
> sure engine and connection have .dialect.name.   Foreign key constraints 
> don't matter on SQLite unless you've actually enabled them, which is rare.   
> I'd still use an event though so at least the behavior is transparent.
> 
> @event.listens_for(my_table, "before_create")
> def add_fk(table, conn, **kw):
>     if conn.dialect.name != 'mssql':
>         table.append_constraint(ForeignKeyConstraint(...))
> 
> tricky though to modify the table metadata within a "create" event in the 
> case that the table is created multiple times in an app.  you can put a flag 
> in table.info, like "table.info['added_the_fk'] = True", to keep track of 
> things.
> 
> 
> 
> On Jul 7, 2012, at 12:59 AM, alex bodnaru wrote:
> 
>>
>> hello mike and thanks for your answer.
>>
>> no problem with ForeignKeyConstraint, but wouldn't AddConstraint go the alter
>> way? in this case, it will be ignored by the sqlite dialect.
>>
>> what i was looking for was more like:
>>
>> from sqlalchemy... import get_dialect
>>
>> ....
>> fk_parms = dict(.....)
>> if get_dialect() != 'mssql':
>>      fk_parms.update(onupdate='restrict')
>> fk = ForeignKey(**fk_parms)
>>
>> would the dialect be accessible from the engine, metadata etc?
>>
>> thanks in advance,
>> alex
>>
>>
>> On 07/06/2012 11:39 PM, Michael Bayer wrote:
>>> you'd use ForeignKeyConstraint along with the AddConstraint directive, and 
>>> limit it per-dialect using create/drop events as documented at 
>>> http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html#controlling-ddl-sequences
>>>  .
>>>
>>>
>>> On Jul 6, 2012, at 1:30 PM, alex bodnaru wrote:
>>>
>>>>
>>>> hello friends,
>>>>
>>>> i need to define a foreign key differently for different dialects:
>>>> ondelete='restrict' for most engines, but nothing (implied and not 
>>>> recognized)
>>>> for mssql.
>>>>
>>>> could you help?
>>>>
>>>> thanks in advance,
>>>> alex
>>>>
>>>> -- 
>>>> 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 
>>>> sqlalchemy+unsubscr...@googlegroups.com.
>>>> 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 sqlalchemy@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> sqlalchemy+unsubscr...@googlegroups.com.
>> 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 sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to