Opened 10 years ago
Closed 10 years ago
#25088 closed Uncategorized (invalid)
Migrations fail when change upload_to from function to sting type
| Reported by: | argaliev | Owned by: | nobody |
|---|---|---|---|
| Component: | Migrations | Version: | 1.8 |
| 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
In first migration function make_upload_path was passed to upload_to property of FIleField:
def make_upload_path(instance, filename):
return 'auto_scripts/{0}/{1}'.format(instance.id,filename)
class file_imports(models.Model):
orig_file = models.FileField(upload_to=make_upload_path, blank=True, null=True)
Then upload_to was changed to hardcoded string and function make_upload_path was deleted.
orig_file = models.FileField(upload_to='auto_scripts/', blank=True, null=True)
and getting following error when starting makemigrations:
......
File "...../main/migrations/0001_initial.py", line 108, in Migration
('orig_file', models.FileField(upload_to=main.models.make_upload_path, null=True,
AttributeError: 'module' object has no attribute 'make_upload_path'
Looks like migrations still want to see old function make_upload_path in code, but it does't need anymore.
Note:
See TracTickets
for help on using tickets.
You need to keep the
make_upload_path()function around as long as it's referenced in migrations. See https://docs.djangoproject.com/en/stable/topics/migrations/#historical-models.