Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#22030 closed Bug (fixed)

AttributeError: 'CharField' object has no attribute 'swappable_setting'

Reported by: bmispelon Owned by: Baptiste Mispelon <bmispelon@…>
Component: Migrations Version: 1.7-alpha-1
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Here's how to reproduce:

Create an app with a simple (and put it in settings.INSTALLED_APPS):

from django.db import models

class Foo(models.Model):

Run makemigrations and then migrate.

Then change the Foo model to be:

class Foo(models.Model):
    foo = models.CharField(max_length=10, default='')

After that, running makemigrations breaks with the following traceback:

Traceback (most recent call last):
  File "", line 10, in <module>
  File "./django/core/management/", line 427, in execute_from_command_line
  File "./django/core/management/", line 419, in execute
  File "./django/core/management/", line 287, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "./django/core/management/", line 336, in execute
    output = self.handle(*args, **options)
  File "./django/core/management/commands/", line 80, in handle
    changes = autodetector.changes(graph=loader.graph, trim_to_apps=app_labels or None)
  File "./django/db/migrations/", line 33, in changes
    changes = self._detect_changes()
  File "./django/db/migrations/", line 236, in _detect_changes
    swappable_setting = new_apps.get_model(app_label, model_name)._meta.get_field_by_name(field_name)[0].swappable_setting
AttributeError: 'CharField' object has no attribute 'swappable_setting'

Breakage was introduced in commit 11c021336c8cb1c92be998f1a44c89a746275107.

Change History (5)

comment:1 Changed 3 years ago by bmispelon

  • Version changed from 1.6 to 1.7-alpha-1

comment:2 Changed 3 years ago by bmispelon

  • Has patch set

Failing test case and tentative fix there:

comment:3 Changed 3 years ago by timo

  • Triage Stage changed from Unreviewed to Ready for checkin

comment:4 Changed 3 years ago by Baptiste Mispelon <bmispelon@…>

  • Owner set to Baptiste Mispelon <bmispelon@…>
  • Resolution set to fixed
  • Status changed from new to closed

In 6873eeeefbc3a081c98351ff25b4cdc42dbf3d7d:

Fixed #22030 -- Don't assume that all fields have a swappable_setting attribute.

comment:5 Changed 3 years ago by Andrew Godwin <andrew@…>

In 3c547a423f5394d816b5a942570abd904f07bfba:

Merge pull request #2270 from bmispelon/ticket-22030

Fixed #22030 -- Don't assume that all fields have a swappable_setting at...

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