Opened 4 years ago

Closed 4 years ago

#22344 closed Bug (fixed)

Migration from ForeignKey to FileField fails: AttributeError: 'NoneType' object has no attribute 'to'

Reported by: Daniel Hahler Owned by: nobody
Component: Migrations Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The following migration fails to change the ForeignKey field into a FileField:

  Applying app.0017_auto_20140326_1849...Traceback (most recent call last):
  File "…/", line 62, in <module>
  File "…/django-master/django/core/management/", line 427, in execute_from_command_line
  File "…/django-master/django/core/management/", line 419, in execute
  File "…/django-master/django/core/management/", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "…/django-master/django/core/management/", line 337, in execute
    output = self.handle(*args, **options)
  File "…/django-master/django/core/management/commands/", line 145, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "…/django-master/django/db/migrations/", line 60, in migrate
    self.apply_migration(migration, fake=fake)
  File "…/django-master/django/db/migrations/", line 94, in apply_migration
    migration.apply(project_state, schema_editor)
  File "…/django-master/django/db/migrations/", line 97, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "…/django-master/django/db/migrations/operations/", line 127, in database_forwards =
AttributeError: 'NoneType' object has no attribute 'to'

ipdb> from_model, from_field, from_field.rel, to_field, to_field.rel

<class '__fake__.MainFile'>,
<django.db.models.fields.related.ForeignKey: file>
<django.db.models.fields.related.ManyToOneRel object at 0x4385410>
<django.db.models.fields.files.FileField: file>

Change History (4)

comment:1 Changed 4 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:2 Changed 4 years ago by Stephen Burrows

I just ran into this with altering an M2M field to a text field. Workaround: Remove first, then re-add as text field.

Last edited 4 years ago by Stephen Burrows (previous) (diff)

comment:3 Changed 4 years ago by wlan

I just had the same problem but with altering an M2M field into a booleanfield, the workaround posted by melinath worked for me as well.

comment:4 Changed 4 years ago by Andrew Godwin

Resolution: fixed
Status: newclosed

Can no longer reproduce, so marking as fixed.

Note: See TracTickets for help on using tickets.
Back to Top