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/35287e93-91aa-4fbc-a872-875d78e0e0cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to