2017-04-26 142 views
1

我最近從Django 1.3升級到1.8,並且遇到了嘗試進行遷移設置時遇到的問題。以前使用過South,並通過settings.py卸載它,並在每個應用中刪除它們的文件夾。KeyError:u'editable'首次執行./manage.py遷移時

當試圖安裝遷移我得到這個錯誤:

[email protected]:/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' 

運行makemigrations

[email protected]:/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' 

時一直在抓取互聯網試圖找到一個解決這個我也得到同樣的錯誤,但沒有骰子。

+0

我希望你先運行'''makemigrations'''? –

+0

謝謝@SijanBhandari我也從那裏得到了同樣的錯誤 –

+0

請將您的models.py與遷移相關。 –

回答

0

我終於找到了問題。它從閱讀這個文件

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

它說發現

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 

我的代碼有auto_now_add=True時間字段,其從與頸部鬍鬚這裏閱讀故事後我所知是壞:Django auto_now and auto_now_add

del kwargs['editable']部分拋出錯誤。

+0

猴子補丁這種方法 – metaphy

相關問題