我在django 1.7
中运行python manage.py syncdb
时遇到错误
我使用的是Python2.7,但我在Python 3.4.3中得到完全相同的错误
$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 13, in <module>
execute_from_command_line(sys.argv)
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/Users/HK/anaconda/lib/python2.7/site-packages/debug_toolbar/apps.py", line 15, in ready
dt_settings.patch_all()
File "/Users/HK/anaconda/lib/python2.7/site-packages/debug_toolbar/settings.py", line 232, in patch_all
patch_root_urlconf()
File "/Users/HK/anaconda/lib/python2.7/site-packages/debug_toolbar/settings.py", line 220, in patch_root_urlconf
reverse('djdt:render_panel')
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/core/urlresolvers.py", line 522, in reverse
app_list = resolver.app_dict[ns]
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/core/urlresolvers.py", line 329, in app_dict
self._populate()
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/core/urlresolvers.py", line 269, in _populate
for pattern in reversed(self.url_patterns):
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/core/urlresolvers.py", line 372, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/core/urlresolvers.py", line 366, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/Users/HK/anaconda/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/HK/website/mor36/src/mor36/urls.py", line 13, in <module>
url(r'^admin/', include(admin.site.urls)),
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 262, in urls
return self.get_urls(), self.app_name, self.name
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 246, in get_urls
url(r'^%s/%s/' % (model._meta.app_label, model._meta.model_name), include(model_admin.urls))
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/contrib/admin/options.py", line 598, in urls
return self.get_urls()
File "/Users/HK/anaconda/lib/python2.7/site-packages/cms/admin/pageadmin.py", line 139, in get_urls
url_patterns += super(PageAdmin, self).get_urls()
File "/Users/HK/anaconda/lib/python2.7/site-packages/cms/admin/placeholderadmin.py", line 121, in get_urls
from cms.urls import SLUG_REGEXP
File "/Users/HK/anaconda/lib/python2.7/site-packages/cms/urls.py", line 20, in <module>
urlpatterns = get_app_patterns()
File "/Users/HK/anaconda/lib/python2.7/site-packages/cms/appresolver.py", line 196, in get_app_patterns
current_site = Site.objects.get_current()
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/contrib/sites/models.py", line 54, in get_current
current_site = self.get(pk=sid)
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/db/models/query.py", line 351, in get
num = len(clone)
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/db/models/query.py", line 122, in __len__
self._fetch_all()
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/db/models/query.py", line 966, in _fetch_all
self._result_cache = list(self.iterator())
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/db/models/query.py", line 265, in iterator
for row in compiler.results_iter():
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 701, in results_iter
for rows in self.execute_sql(MULTI):
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 787, in execute_sql
cursor.execute(sql, params)
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Users/HK/anaconda/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
return Database.Cursor.execute(self, query, params)
**django.db.utils.OperationalError: no such table: django_site**
答案 0 :(得分:3)
我可以看到你正在使用django-CMS,我遇到了同样的问题。我可以假设Django的新版本可能存在问题。
根本原因是还没有创建Django表,但是cms尝试引用它们(特别是从Sites框架获取当前站点)
这不是以前版本的Django中的问题,因为你通常会python manage.py sycndb
(至少在Django 1.9中删除)并且该命令创建了所有django表。
所以要解决这个问题 - 您需要在settings.py
中注释掉与django CMS相关的所有内容,运行python manage.py migrate
以迁移Django表,然后取消注释cms内容并再次迁移,然后它就不应该不再是一个问题了。 (有时它也有助于评论当前项目来自已安装的应用程序以及cms内容,以便Django 1.9检查不会检查你的urls.py,其中包含与cms相关的条目)。
如果您在Django&lt; 1.9但是&gt;上遇到同样的问题1.7首先尝试执行syncdb。
希望对遇到类似问题的人有所帮助。
答案 1 :(得分:0)
如果它不存在,请将以下内容添加到settings.py中的INSTALLED_APPS属性中:
distance = e^x
并在settings.py中添加'django.contrib.sites'
。
在Django 1.7+中,进行数据库更改的首选方法是使用迁移管理命令:
SITE_ID = 1
这应该可以解决你的问题。