1

I recently upgraded from Django 1.3 to 1.8 and have been experiencing issues trying to get setup on migrations. Previously used South and have uninstalled it through settings.py and deleted their folders in each app.

When trying to setup migrations I get this error:

root@ip:/home/# python manage.py migrate
Operations to perform:
  Synchronize unmigrated apps: web_forms, staticfiles, tinymce, messages, miscellaneous, generalpagess, gallery, template, import, navigation, frontpage, association
  Apply all migrations: admin, contenttypes, sites, auth, sessions
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 222, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/usr/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 100, in migrate
    state.apps  # Render all real_apps -- performance critical
  File "/usr/lib/python2.7/dist-packages/django/utils/functional.py", line 59, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/lib/python2.7/dist-packages/django/db/migrations/state.py", line 166, in apps
    return StateApps(self.real_apps, self.models)
  File "/usr/lib/python2.7/dist-packages/django/db/migrations/state.py", line 226, in __init__
    self.real_models.append(ModelState.from_model(model, exclude_rels=True))
  File "/usr/lib/python2.7/dist-packages/django/db/migrations/state.py", line 345, in from_model
    name, path, args, kwargs = field.deconstruct()
  File "/usr/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 1253, in deconstruct
    del kwargs['editable']
KeyError: u'editable'

I am also getting the same error when running makemigrations

root@:/home/# python manage.py makemigrations
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.7/dist-packages/django/core/management/commands/makemigrations.py", line 99, in handle
    ProjectState.from_apps(apps),
  File "/usr/lib/python2.7/dist-packages/django/db/migrations/state.py", line 178, in from_apps
    model_state = ModelState.from_model(model)
  File "/usr/lib/python2.7/dist-packages/django/db/migrations/state.py", line 345, in from_model
    name, path, args, kwargs = field.deconstruct()
  File "/usr/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 1253, in deconstruct
    del kwargs['editable']
KeyError: u'editable'

Have been crawling the internet trying to find a resolution to this, but no dice.

Alex Stewart
  • 730
  • 3
  • 12
  • 30

2 Answers2

2

I had a similar issue when I had a model that had a DatetimeField. The model was something like bellow

class MyModel(models.Model):
    time = models.DatetimeField(auto_now_add=True)
    time.editable = True

Removing the last line time.editable = True allowed me to run the python manage.py makemigrations appname command then after.

Tara Prasad Gurung
  • 3,422
  • 6
  • 38
  • 76
1

I finally found the issue. It found out from reading this file

File "/usr/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 1253`

Which says

def deconstruct(self):
    name, path, args, kwargs = super(DateField, self).deconstruct()
    if self.auto_now:
        kwargs['auto_now'] = True
    if self.auto_now_add:
        kwargs['auto_now_add'] = True
    if self.auto_now or self.auto_now_add:
        del kwargs['editable']
        del kwargs['blank']
    return name, path, args, kwargs

My code had auto_now_add=True for time fields which from what I can gather is bad after reading stories from the neck beards here: Django auto_now and auto_now_add

The del kwargs['editable'] part was throwing the error.

Alex Stewart
  • 730
  • 3
  • 12
  • 30