[Django] #22344: Migration from ForeignKey to FileField fails: AttributeError: 'NoneType' object has no attribute 'to'

20 views
Skip to first unread message

Django

unread,
Mar 26, 2014, 2:33:42 PM3/26/14
to django-...@googlegroups.com
#22344: Migration from ForeignKey to FileField fails: AttributeError: 'NoneType'
object has no attribute 'to'
----------------------------+--------------------
Reporter: blueyed | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
The following migration fails to change the ForeignKey field into a
FileField:
{{{
migrations.AlterField(
model_name='mainfile',
name='file',
field=models.FileField(upload_to='...'),
),
}}}
{{{
Applying app.0017_auto_20140326_1849...Traceback (most recent call
last):
File "…/manage.py", line 62, in <module>
execute_from_command_line(sys.argv)
File "…/django-master/django/core/management/__init__.py", line 427, in
execute_from_command_line
utility.execute()
File "…/django-master/django/core/management/__init__.py", line 419, in
execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "…/django-master/django/core/management/base.py", line 288, in
run_from_argv
self.execute(*args, **options.__dict__)
File "…/django-master/django/core/management/base.py", line 337, in
execute
output = self.handle(*args, **options)
File "…/django-master/django/core/management/commands/migrate.py", line
145, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "…/django-master/django/db/migrations/executor.py", line 60, in
migrate
self.apply_migration(migration, fake=fake)
File "…/django-master/django/db/migrations/executor.py", line 94, in
apply_migration
migration.apply(project_state, schema_editor)
File "…/django-master/django/db/migrations/migration.py", line 97, in
apply
operation.database_forwards(self.app_label, schema_editor,
project_state, new_state)
File "…/django-master/django/db/migrations/operations/fields.py", line
127, in database_forwards
from_field.rel.to = to_field.rel.to
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>
None)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22344>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 28, 2014, 8:19:04 PM3/28/14
to django-...@googlegroups.com
#22344: Migration from ForeignKey to FileField fails: AttributeError: 'NoneType'
object has no attribute 'to'
----------------------------+------------------------------------

Reporter: blueyed | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Changes (by timo):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/22344#comment:1>

Django

unread,
Jun 18, 2014, 3:56:03 AM6/18/14
to django-...@googlegroups.com
#22344: Migration from ForeignKey to FileField fails: AttributeError: 'NoneType'
object has no attribute 'to'
----------------------------+------------------------------------

Reporter: blueyed | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------

Comment (by melinath):

I just ran into this in a simpler case: Removing an M2M field.

--
Ticket URL: <https://code.djangoproject.com/ticket/22344#comment:2>

Django

unread,
Jun 20, 2014, 3:49:04 PM6/20/14
to django-...@googlegroups.com
#22344: Migration from ForeignKey to FileField fails: AttributeError: 'NoneType'
object has no attribute 'to'
----------------------------+------------------------------------

Reporter: blueyed | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------

Comment (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.

--
Ticket URL: <https://code.djangoproject.com/ticket/22344#comment:3>

Django

unread,
Sep 5, 2014, 2:32:49 PM9/5/14
to django-...@googlegroups.com
#22344: Migration from ForeignKey to FileField fails: AttributeError: 'NoneType'
object has no attribute 'to'
----------------------------+------------------------------------
Reporter: blueyed | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Changes (by andrewgodwin):

* status: new => closed
* resolution: => fixed


Comment:

Can no longer reproduce, so marking as fixed.

--
Ticket URL: <https://code.djangoproject.com/ticket/22344#comment:4>

Reply all
Reply to author
Forward
0 new messages