Opened 10 years ago
Closed 10 years ago
#24259 closed Uncategorized (invalid)
Django 1.7.4 makes the same migration change when `upload_to` and `validators` are set.
Reported by: | user0007 | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.7 |
Severity: | Normal | Keywords: | migrations |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
My model:
from myapps.core.fstorages.util import get_upload_path from myapps.core.validators.base import FileValidator class Entry(models.Model): .... photo = models.ImageField( max_length=200, upload_to=get_upload_path, validators=[ FileValidator( allowed_extensions=['png', 'jpg'], max_size=10 * 1024 * 1024, ) ] )
Running makemigrations:
$ python manage.py makemigrations entries
Migration:
class Migration(migrations.Migration): ... operations = [ migrations.AlterField( model_name='entry', name='photo', field=models.ImageField(upload_to=myapps.core.fstorages.util.get_upload_path, max_length=200, verbose_name='photo', validators=[myapps.core.validators.base.FileValidator(allowed_extensions=[b'png', b'jpg'], max_size=10485760)]), preserve_default=True, ), ]
Running migrations
$ python manage.py migrate entries
OK
Running migrations (once again):
$ python manage.py migrate entries
Your models have changes that are not yet reflected in a migration, and so won't be applied. Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
So I do:
$ python manage.py makemigrations entries
and get the same migration. Every time I run makemigrations Django creates the same migration for field "photo" .. is there some bug?
Thanks.
PS. FileValidator and get_upload_path source:
def get_upload_path(instance, filename): return "/1/2/3" @deconstructible class FileValidator(object): def __init__(self, *args, **kwargs): self.allowed_extensions = kwargs.pop('allowed_extensions', ()) self.allowed_mimetypes = kwargs.pop('allowed_mimetypes', ()) self.min_size = kwargs.pop('min_size', 0) self.max_size = kwargs.pop('max_size', None) def __call__(self, value): # ...code here pass
Please ready about adding an
__eq__()
method to your validator: https://docs.djangoproject.com/en/1.7/topics/migrations/#adding-a-deconstruct-method