0

I've made custom field, which is basically "upgraded" ForeignKey field. However, I forgot to set on_delete=models.PROTECT as default (desired default behaviour of that field).

class MyReferenceField( models.ForeignKey ):
    def __init__(self, *args, **kwargs):
        my_args = { 
            'null': True,
            'blank': True,
            'to': Photo,
            #'on_delete': models.PROTECT,  #forgotten property, that I'm adding to the field
        }
        my_args.update( kwargs )
        super(MyReferenceField, self).__init__(**my_args)

    ... MORE STUFF ...

Nothing changes if I add on_delete to kwargs. If I add on_delete to constructor call(ie. manually on each usage of field), then it works.

I want to update every usage/instance of that field, to have on_delete set to the PROTECT. So, how can I make Django know about change of default behavior/properties of a field?

Edit - clarifications: I'm using the native migrations as of Django 1.7. I've found deconstruct(), but I don't know how exactly should I use it for this case.

kravemir
  • 10,636
  • 17
  • 64
  • 111

1 Answers1

0

Depending on if you are using the native migrations as of Django 1.7 or South you probably need to either add a deconstruct()-method to your custom field or a south_field_triple.

arie
  • 18,737
  • 5
  • 70
  • 76