Opened 10 years ago
Closed 10 years ago
#24563 closed Bug (duplicate)
Migration for M2M Field fails with FieldDoesNotExist when removing null=True from model
Reported by: | Ronny Vedrilla | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.8 |
Severity: | Normal | Keywords: | migrations, many2many, nullable |
Cc: | me@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I removed the null=True as suggested in django 1.8 warnings from my M2M field in the model.
django migrations created the following:
class Migration(migrations.Migration): [...] operations = [ migrations.AlterField(model_name='project', name='my_field', field=models.ManyToManyField(related_name='in_charge_projects', verbose_name='label', to='account.Employee', blank=True), ), [...] ]
I get the following error:
"django.core.exceptions.FieldDoesNotExist: Project_my_field has no field named None"
Change History (9)
comment:1 by , 10 years ago
Cc: | added |
---|
comment:2 by , 10 years ago
Description: | modified (diff) |
---|---|
Resolution: | → needsinfo |
Status: | new → closed |
comment:3 by , 10 years ago
Resolution: | needsinfo |
---|---|
Status: | closed → new |
I had exactly the same problem. The following is a stack trace for the error.
File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line utility.execute() File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 330, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 390, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 441, in execute output = self.handle(*args, **options) File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 221, in handle executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial) File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 110, in migrate self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial) File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 147, in apply_migration state = migration.apply(state, schema_editor) File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/migration.py", line 115, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/operations/fields.py", line 201, in database_forwards schema_editor.alter_field(from_model, from_field, to_field) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 469, in alter_field return self._alter_many_to_many(model, old_field, new_field, strict) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/schema.py", line 232, in _alter_many_to_many override_uniques=(new_field.m2m_field_name(), new_field.m2m_reverse_field_name()), File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/schema.py", line 137, in _remake_table self.create_model(temp_model) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 268, in create_model columns = [model._meta.get_field(field).column for field in fields] File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 554, in get_field raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name)) django.core.exceptions.FieldDoesNotExist: Forum_subscriptions has no field named None
comment:4 by , 10 years ago
Just looking noticed at https://docs.djangoproject.com/en/1.8/ref/models/meta/ there was a change to the get_field()
method in 1.8. Maybe create_model is still assuming the old functionality of get_field()
here? Maybe what is needed is something like this:
columns = [model._meta.get_field(field).column for field in fields if not field.many_to_many]
I have not tested, but am really just guessing at what looks right from the docs.
comment:6 by , 10 years ago
comment:7 by , 10 years ago
Is this on the 1.8.x development branch or the 1.8.0 release. We fixed a few bugs in the upcoming 1.8.1 release: https://docs.djangoproject.com/en/dev/releases/1.8.1/
comment:8 by , 10 years ago
The 1.8.0 release as given by pip.
I guess this is a dup then. Did not find the other ones when I did a search for it.
comment:9 by , 10 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Can not reproduce this locally.
Please provide a test project, where this error will exists.