0

我正在使用 Django 1.11 来制作应用程序“cnfs”,并且我正在使用 MYSQL 数据库。我经常遇到这个问题,当我输入以下代码时,我会收到这样的错误:

$python manage.py migrate

系统检查发现了一些问题: 警告:?:(mysql.W002)MySQL 严格模式未设置为数据库连接“默认”提示:MySQL 的严格模式通过升级警告修复了 MySQL 中的许多数据完整性问题,例如插入时数据截断进入错误。强烈建议您激活它。请参阅:https ://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode 要执行的操作:应用所有迁移:admin、auth、cnfs、contenttypes、sites 运行迁移:没有要应用的迁移。回溯(最近一次调用):文件“manage.py”,第 22 行,在 execute_from_command_line(sys.argv) 文件“/home/ubuntu/.local/lib/python2.7/site-packages/django/core/management /初始化.py”,第 363 行,在 execute_from_command_line utility.execute () 文件“/home/ubuntu/.local/lib/python2.7/site-packages/django/core/management/init.py”,第 355 行,在执行 self.fetch_command(subcommand).run_from_argv(self.argv) 文件“/home/ubuntu/.local/lib/python2.7/site-packages/django/core/management/base. py”,第 283 行,在 run_from_argv self.execute(*args, **cmd_options) 文件“/home/ubuntu/.local/lib/python2.7/site-packages/django/core/management/base.py”中,第 330 行,在执行输出 = self.handle(*args, **options) 文件“/home/ubuntu/.local/lib/python2.7/site-packages/django/core/management/commands/migrate.py”,第 227 行,在句柄 self.verbosity、self.interactive、connection.alias、apps=post_migrate_apps、plan=plan、文件“/home/ubuntu /.local/lib/python2.7/site-packages/django/core/management/sql.py”,第 53 行,在 emit_post_migrate_signal **kwargs 文件“/home/ubuntu/.local/lib/python2.7/site -packages/django/dispatch/dispatcher.py”,第 193 行,在 self._live_receivers(sender) 文件“/home/ubuntu/.local/lib/python2.7/site-packages/django/contrib/sites/management.py”,第 20 行,如果不是 Site.objects.using(using).exists(),则在 create_default_site 中:文件“/home/ubuntu/ .local/lib/python2.7/site-packages/django/db/models/query.py”,第 670 行,存在返回 self.query.has_results(using=self.db) 文件“/home/ubuntu/. local/lib/python2.7/site-packages/django/db/models/sql/query.py",第 517 行,在 has_results 中返回 compiler.has_results() 文件"/home/ubuntu/.local/lib/python2.7/site-packages/django/db/models/sql/compiler.py”,第 845 行,在 has_results 返回 bool(self.execute_sql(SINGLE)) 文件“/home /ubuntu/.local/lib/python2.7/site-packages/django/db/models/sql/compiler.py",第 886 行,在 execute_sql 中引发 original_exception django.db.utils.ProgrammingError: (1146, "Table ' cnfs.django_site' 不存在")在 has_results 返回 bool(self.execute_sql(SINGLE)) 文件“/home/ubuntu/.local/lib/python2.7/site-packages/django/db/models/sql/compiler.py”,第 886 行,在 execute_sql引发 original_exception django.db.utils.ProgrammingError:(1146,“表 'cnfs.django_site' 不存在”)在 has_results 返回 bool(self.execute_sql(SINGLE)) 文件“/home/ubuntu/.local/lib/python2.7/site-packages/django/db/models/sql/compiler.py”,第 886 行,在 execute_sql引发 original_exception django.db.utils.ProgrammingError:(1146,“表 'cnfs.django_site' 不存在”)在 execute_sql 中引发 original_exception django.db.utils.ProgrammingError:(1146,“表 'cnfs.django_site' 不存在”)在 execute_sql 中引发 original_exception django.db.utils.ProgrammingError:(1146,“表 'cnfs.django_site' 不存在”)

我确实在这上面花了几天时间,当我使用默认的 django 数据库引擎 sqlite3 时,我没有遇到这个问题。我试过这样做:$python manage.py migrate sites

我的 SITE_ID 设置设置为 1。我尝试从 INSTALLED_APPS 设置中删除“django.contrib.sites”,但这会引发此错误:

内部服务器错误:/ Traceback(最近一次调用最后一次):文件“/home/ubuntu/.local/lib/python2.7/site-packages/django/core/handlers/exception.py”,第 41 行,在内部响应中= get_response(request) 文件“/home/ubuntu/.local/lib/python2.7/site-packages/django/utils/deprecation.py”,第 138 行,调用中 response = self.process_request(request) 文件“/home/ubuntu/.local/lib/python2.7/site-packages/subdomains/middleware.py”,第 62 行,在 process_request super(SubdomainURLRoutingMiddleware, self).process_request(request )文件“/home/ubuntu/.local/lib/python2.7/site-packages/subdomains/middleware.py”,第38行,在process_request(self.get_domain_for_request(request),request.get_host())文件“ /home/ubuntu/.local/lib/python2.7/site-packages/subdomains/middleware.py”,第 31 行,在 get_domain_for_request 返回 get_domain() 文件“/home/ubuntu/.local/lib/python2.7/site-packages/subdomains/utils.py”,第 12 行,在 current_site_domain 从 django.contrib.sites.models 导入站点文件“ /home/ubuntu/.local/lib/python2.7/site-packages/django/contrib/sites/models.py”,第 84 行,在类站点(models.Model)中:文件“/home/ubuntu/.local /lib/python2.7/site-packages/django/db/models/base.py”,第 118 行,在新的 “INSTALLED_APPS”。% (module, name) RuntimeError: Model class django.contrib.sites.models.Site 没有声明明确的 app_label 并且不在 INSTALLED_APPS 的应用程序中。

任何建议将不胜感激。

谢谢。

4

1 回答 1

3

django.contrib.sites从已安装的应用程序中取消注释

然后

python manage.py migrate sites
python manage.py migrate

如果数据库中的表很少,请删除表然后运行

于 2017-06-19T11:22:58.980 回答