Il giorno venerdì 14 novembre 2014 23:35:46 UTC+1, Markus Holtermann ha 
scritto:
>
> Hey Nicola,
>
> Django's migration system doesn't natively support "drop this foreign key 
> constraint from the database", because you shouldn't be able to run into 
> such a situation with the migration system at all (if you do, that's a bug 
> from my point of view). I suggest you go with a "RunSQL" operation where 
> you drop the constraint: 
> https://docs.djangoproject.com/en/1.7/ref/migration-operations/#django.db.migrations.operations.RunSQL
>
>
The problem here is that django does not create foreign key with a 
predefined name so I have to do a query using different sql for each 
supported db to find the foreign key name and then issue the sql statements 
using RunSQL, I think that in my case the simplest solution is to set 
db_constraint=False on the foreign key that need a cascade enforcement in 
the database and then reuse the sql I already have to create the constraint 
inside the database,

seems no better solution is possibile, if there is a bug here is in django 
that don't allow constraint enforcement at the db level and try to emulate 
what the db can do natively and much quicker

Nicola

 

> /Markus
>
> On Friday, November 14, 2014 4:23:52 PM UTC+1, drakkan wrote:
>>
>> Hi,
>>
>> I'm migrating my app to 1.7 and to builtin django migrations from south, 
>> I need something like this:
>>
>>
>> http://south.readthedocs.org/en/latest/databaseapi.html#db-delete-foreign-key
>>
>> how to remove a foreign key using django builtin migration api?
>>
>> Please note that my purpose is to remove the foreign key and then add it 
>> back with "ON DELETE CASCADE" constraint, actually I use the south api to 
>> remove the foreign key and then database specific sql to add it with the 
>> constraint I need. I would like to avoid to use sql specific code to find 
>> the foreign key too,
>>
>> thanks
>> Nicola
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6c300aca-c1e0-4898-9808-127131c090e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to