Opened 6 years ago

Closed 6 years ago

#28080 closed Bug (duplicate)

Migration guesses wrong namespace for Enum defined on class

Reported by: Curtis Maloney Owned by: nobody
Component: Migrations Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have the following model:

class Question(models.Model):
    class MODE(enum.IntEnum):
        TEXT = 1
        NUMBER = 2
        CHOICE = 3
    question = models.TextField()
    label_text = models.CharField(max_length=200)
    hint = models.CharField(max_length=200, blank=True)
    mode = models.IntegerField(
        choices=((x.value, for x in MODE),

The initial migration generated produces:

                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('question', models.TextField()),
                ('label_text', models.CharField(max_length=200)),
                ('hint', models.CharField(blank=True, max_length=200)),
                ('mode', models.IntegerField(choices=[(1, 'Text'), (2, 'Number'), (3, 'Choice')], default=sheets.models.MODE(1))),

Notice the default... it's sheets.models.MODE instead of sheets.models.Question.MODE

This causes the following traceback:

Traceback (most recent call last):
  File "", line 22, in <module>
  File ".../venv/lib/python3.5/site-packages/django/core/management/", line 363, in execute_from_command_line
  File ".../venv/lib/python3.5/site-packages/django/core/management/", line 355, in execute
  File ".../venv/lib/python3.5/site-packages/django/core/management/", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File ".../venv/lib/python3.5/site-packages/django/core/management/", line 330, in execute
    output = self.handle(*args, **options)
  File ".../venv/lib/python3.5/site-packages/django/core/management/commands/", line 83, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File ".../venv/lib/python3.5/site-packages/django/db/migrations/", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
  File ".../venv/lib/python3.5/site-packages/django/db/migrations/", line 52, in __init__
  File ".../venv/lib/python3.5/site-packages/django/db/migrations/", line 203, in build_graph
  File ".../venv/lib/python3.5/site-packages/django/db/migrations/", line 114, in load_disk
    migration_module = import_module("%s.%s" % (module_name, migration_name))
  File ".../venv/lib/python3.5/importlib/", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 673, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File ".../cloudselect/sheets/migrations/", line 10, in <module>
    class Migration(migrations.Migration):
  File ".../cloudselect/sheets/migrations/", line 25, in Migration
    ('mode', models.IntegerField(choices=[(1, 'Text'), (2, 'Number'), (3, 'Choice')], default=sheets.models.MODE(1))),
AttributeError: module 'sheets.models' has no attribute 'MODE'

Change History (1)

comment:1 Changed 6 years ago by Simon Charette

Resolution: duplicate
Status: newclosed

Duplicate of #27914.

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