升级到Django 1.11.4 ImportError

时间:2017-09-01 14:42:42

标签: python django python-2.7

我试图用Python 2.7.11将Django从1.10.7升级到1.11.4。我已经运行pip install Django -U并且python -c "import django; print django.get_version()"确认已安装Django 1.11.4。但是,当我去运行测试时,我得到ImportError: No module named notmigrations。有没有人有任何建议?

这是完整的堆栈跟踪:

Traceback (most recent call last):
  File "./manage.py", line 25, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/commands/test.py", line 29, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/commands/test.py", line 62, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/test/runner.py", line 601, in run_tests
    old_config = self.setup_databases()
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/test/runner.py", line 546, in setup_databases
    self.parallel, **kwargs
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/test/utils.py", line 187, in setup_databases
    serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 69, in create_test_db
    run_syncdb=True,
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/__init__.py", line 130, in call_command
    return command.execute(*args, **defaults)
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 83, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/db/migrations/executor.py", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/db/migrations/loader.py", line 52, in __init__
    self.build_graph()
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/db/migrations/loader.py", line 203, in build_graph
    self.load_disk()
  File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/db/migrations/loader.py", line 82, in load_disk
    module = import_module(module_name)
  File "/usr/local/lib/python2.7.11/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named notmigrations

2 个答案:

答案 0 :(得分:8)

您似乎在notmigrations设置中使用MIGRATION_MODULES来禁用迁移(如this post中所述)。

在Django 1.9+中,您应该使用None而不是像'notmigrations'release notes)这样的虚假模块名称。

答案 1 :(得分:2)

对于Django 2.0,我按照here描述创建设置文件,内容如下:

from settings import *

class DisableMigrations(object):
    def __contains__(self, item):
        return True

    def __getitem__(self, item):
        return None

MIGRATION_MODULES = DisableMigrations()

并使用测试新创建的设置

运行我的测试