Opened 9 years ago

Closed 9 years ago

#25908 closed Uncategorized (invalid)

migrations fail when default function is removed

Reported by: Rapolas K. Owned by: nobody
Component: Migrations Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Whenever you set a default value for a model field to a function and make a migration, you can't remove the function afterwards. Migration fails to find the function in the module.

For example if you make a migration of this code:

def my_value():
    return 'a'

class MyModel(models.Model):
    myfield = models.CharField(max_length=10, default=my_value)

you can't remove my_value function even if you remove default from the field. And then you have to leave something like this in your code for migrations to work:

def my_value(): pass

or

my_value = lambda: None

It is not a problem for me, as my project is small and I don't mind recreating migrations without default function, but I see this as an issue because you might have to leave some dead code in your app, just for the migrations to work.

Change History (1)

comment:1 by Tim Graham, 9 years ago

Resolution: invalid
Status: newclosed

Correct, this is a documented restriction. You can use squashmigrations if you wish to remove old references.

Note: See TracTickets for help on using tickets.
Back to Top