Opened 7 years ago

Closed 7 years ago

#27530 closed Uncategorized (invalid)

Referencing a function in a model field definition, and then removing that reference (and function) after running a migration raises an exception

Reported by: Jesse Owned by: nobody
Component: Uncategorized Version: 1.10
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

With a FileField you can define a function for the upload_to argument. If you reference a function within that field, and then decide to modify the field later by removing the function reference (and also the function), the migrations will cause the server to fail to start because it can't find the function that was previously referenced.

For example:

def destination():
  return "path"

...

file = models.FileField(upload_to=destination)

Then later on I decide I don't need the function

file = models.FileField(upload_to="hardcoded path")

Now whenever I try to run the server locally or do a migration, I get: "AttributeError: 'module' object has no attribute 'destination'". The only meaningful workaround is to delete all migrations

Change History (1)

comment:1 by Simon Charette, 7 years ago

Resolution: invalid
Status: newclosed

This a documented caveat of historical models.

You can either can squash these migrations or copy your upload_to function definition into the migration files referencing it.

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