0

我想django.contrib.sites从我的django项目中删除。

当我尝试删除时,在启动服务器时出现以下错误:

/usr/local/lib/python3.5/site-packages/django/db/models/fields/subclassing.py:22: RemovedInDjango110Warning: SubfieldBase has been deprecated. Use Field.from_db_value instead.
web_1 |   RemovedInDjango110Warning)
web_1 | 
web_1 | /usr/local/lib/python3.5/site-packages/django/db/models/fields/subclassing.py:22: RemovedInDjango110Warning: SubfieldBase has been deprecated. Use Field.from_db_value instead.
web_1 |   RemovedInDjango110Warning)
web_1 | 
web_1 | Performing system checks...
web_1 | 
web_1 | System check identified no issues (0 silenced).
web_1 | Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f154e979048>
web_1 | Traceback (most recent call last):
web_1 |   File "/usr/local/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
web_1 |     fn(*args, **kwargs)
web_1 |   File "/usr/local/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
web_1 |     self.check_migrations()
web_1 |   File "/usr/local/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 163, in check_migrations
web_1 |     executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
web_1 |   File "/usr/local/lib/python3.5/site-packages/django/db/migrations/executor.py", line 20, in __init__
web_1 |     self.loader = MigrationLoader(self.connection)
web_1 |   File "/usr/local/lib/python3.5/site-packages/django/db/migrations/loader.py", line 49, in __init__
web_1 |     self.build_graph()
web_1 |   File "/usr/local/lib/python3.5/site-packages/django/db/migrations/loader.py", line 306, in build_graph
web_1 |     _reraise_missing_dependency(migration, parent, e)
web_1 |   File "/usr/local/lib/python3.5/site-packages/django/db/migrations/loader.py", line 276, in _reraise_missing_dependency
web_1 |     raise exc
web_1 |   File "/usr/local/lib/python3.5/site-packages/django/db/migrations/loader.py", line 302, in build_graph
web_1 |     self.graph.add_dependency(migration, key, parent)
web_1 |   File "/usr/local/lib/python3.5/site-packages/django/db/migrations/graph.py", line 126, in add_dependency
web_1 |     parent
web_1 | django.db.migrations.exceptions.NodeNotFoundError: Migration services.0001_initial dependencies reference nonexistent parent node ('sites', '0002_alter_domain_unique')

只有我在项目中所做的修改是,settings.py我添加了以下信息:

SITE_ID = 1

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites'
]

在执行以下命令以在管理页面中查看结果后:

python manage.py makemigrations
python manage.py migrate

现在,当我从设置中删除配置并运行 makemigrations 和 migrate 命令时,出现上述错误。

我正在使用python:3.5Django:1.9使用docker

4

1 回答 1

1

看来是自己解决了。以下是我为解决它所做的事情:

  1. 删除以下内容settings.py

    SITE_ID = 1

‘django.contrib.sites'INSTALLED_APPS

INSTALLED_APPS = [
    ‘django.contrib.sites'
]
  1. 从应用程序(我已导入的应用程序)内的迁移文件夹中删除了自动生成的文件django.contrib.sites Models

  2. 重新运行makemigrationsandmigrate命令。

  3. 一切正常。

谢谢。

于 2016-02-17T08:30:39.107 回答