0

我正在將我的網站升級到Django 1.7.1 - 尤其是要獲得整潔的遷移功能。 但是,我遇到了有關遷移和自定義模型字段的一些問題。自定義模型字段遷移問題

這個最討厭的事情是,回溯不給我那麼多的信息 - 這裏是(刪除出於安全原因,一些路徑):

Traceback (most recent call last): 
    File "PyCharm 3.4.1\helpers\pycharm\django_manage.py", line 23, in <module> 
     run_module(manage_file, None, '__main__', True) 
    File "C:\Python27\Lib\runpy.py", line 176, in run_module 
     fname, loader, pkg_name) 
    File "C:\Python27\Lib\runpy.py", line 82, in _run_module_code 
     mod_name, mod_fname, mod_loader, pkg_name) 
    File "C:\Python27\Lib\runpy.py", line 72, in _run_code 
     exec code in run_globals 
    File "portal\manage.py", line 10, in <module> 
     execute_from_command_line(sys.argv) 
    File "lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line 
     utility.execute() 
    File "lib\site-packages\django\core\management\__init__.py", line 377, in execute 
     self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "lib\site-packages\django\core\management\base.py", line 288, in run_from_argv 
     self.execute(*args, **options.__dict__) 
    File "lib\site-packages\django\core\management\base.py", line 338, in execute 
     output = self.handle(*args, **options) 
    File "lib\site-packages\django\core\management\commands\makemigrations.py", line 90, in handle 
     ProjectState.from_apps(apps), 
    File "lib\site-packages\django\db\migrations\state.py", line 104, in from_apps 
     model_state = ModelState.from_model(model) 
    File "lib\site-packages\django\db\migrations\state.py", line 182, in from_model 
e, 
TypeError: Couldn't reconstruct field image on core.GalleryImage: argument of type 'NoneType' is not iterable 

自定義文件字段是ImageWithThumbnailField來自「舊」索爾縮略圖包。它使用PIL 1.1.7。

我有同場本身並沒有問題,只是這種遷移bug.a

在想,如果你們都遇到了同樣的錯誤,並找到了解決辦法?

+0

我認爲問題是,「老」 SORL-縮略圖不Django的1.7遷移,這基本上意味着一個'deconstruct'提供支持方法在字段類https://docs.djangoproject.com/en/1.7/topics/migrations/#adding-a-deconstruct-method ...你可以繼承他們的領域,並自己添加它,它幾乎是相同的南部地區使用的'south_field_triple'方法 – Anentropic 2014-12-05 14:17:02

+0

是的,我嘗試將解構器類添加到某些字段,但沒有運氣。將添加到其餘的,看看它是否工作。 – rulzart 2014-12-05 14:22:22

+0

你知道deconstructor def的樣子嗎? – rulzart 2014-12-05 14:25:05

回答

2

對於任何人遇到這個問題,這裏是解決方案:

def deconstruct(self): 
    # Use ImageField as path, as the deconstruct() will return ImageWithThumbnailsField 
    field_class = "django.db.models.fields.files.ImageField" 
    name, path, args, kwargs = super(BaseThumbnailField, self).deconstruct() 
    return name, field_class, args, kwargs 
相關問題