Hey Hans, As stated in the Docs (https://docs.djangoproject.com/en/1.7/topics/migrations/#historical-models)
References to functions in field options such as upload_to and limit_choices_to are serialized in migrations, so the functions will need to be kept around for as long as there is a migration referencing them. Any custom model fields will also need to be kept, since these are imported directly by migrations. So, simply open the migration file that has the import to the old function and adjust the reference. Inside the CreateModel operation change ('file', models.FileField(upload_to=example.models.ex_upload_to)), to ('file', models.FileField(upload_to=example.models.ex_upload_to_new)), /Markus On Wednesday, November 12, 2014 5:28:52 PM UTC+1, Hans Lawrenz wrote: > > I'm having a problem generating migrations after changing the function > used for the upload_to parameter on a FileField. After removing the old > function from my code and switching to using a closure to generate the > function used by upload_to I get the following exception upon running > makemigrations: > > AttributeError: 'module' object has no attribute 'story_image_url' > > > I made a simple test using an empty app and just renaming the upload_to > function and get the same results because the existing migration references > the old function. > > Any suggestions on how to handle this beyond keeping a dummy function in > the code? > > Here's an example: > > original models.py: > from django.db import models > def ex_upload_to(instance, filename): > return "foo" > > class MyModel(models.Model): > > file = models.FileField(upload_to=ex_upload_to) > > > > migration: > from __future__ import unicode_literals > from django.db import models, migrations > import example.models > > class Migration(migrations.Migration): > dependencies = [ > ] > > operations = [ > migrations.CreateModel( > name='MyModel', > fields=[ > ('id', models.AutoField(verbose_name='ID', > serialize=False, auto_created=True, primary_key=True)), > ('file', > models.FileField(upload_to=example.models.ex_upload_to)), > ], > > options={ > }, > > bases=(models.Model,), > ), > ] > > > new models.py: > from django.db import models > > def ex_upload_to_new(instance, filename): > return "foo" > > class MyModel(models.Model): > file = models.FileField(upload_to=ex_upload_to_new) > > > > > -- 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/8d0fac4b-24f9-44d4-970b-9222fed3c588%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.