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

カスタム ファイル フィールドは、「古い」sorl-thumbnail パッケージの ImageWithThumbnailField です。PIL 1.1.7 を使用します。

この移行バグを除いて、フィールド自体に問題はありません。

同じエラーに遭遇し、解決策を見つけた人がいるかどうか疑問に思っていましたか?

4

1 に答える 1

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
于 2014-12-05T14:37:21.677 に答える