Den Kasyanov
Den Kasyanov

Reputation: 978

How to properly change Django FileField.upload_to attribute?

I'm trying to rename function used in FileField.upload_to attribute. After I change function name, Django fails on Performing system checks.... And in traceback I see AttributeError: module 'the_app.models' has no attribute 'old_function_name'.

Is it possible to change function name/replace function used in upload_to. And if so, how do I properly do it? Am I correct that rewriting content of old migration (applied on live server) is bad practice.

Upvotes: 1

Views: 571

Answers (1)

dirkgroten
dirkgroten

Reputation: 20672

To answer your question whether it's bad practice: It's something you need to be careful about. You definitely don't want to change anything in existing migrations that would affect the database. But Django puts quite a few things in migration files that don't affect the database. upload_to is one of them (help_text for example is also one of them).

So for changes that don't affect the db, go ahead: change them in your models and change them directly in the old migration files, it won't make any difference whether you've already applied the migration or not.

Upvotes: 4

Related Questions