当我犯下颜色时
我收到以下错误:
django.db.utils.OperationalError:没有这样的表:django_site
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 338, in execute
django.setup()
File "C:\Python27\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models()
File "C:\Python27\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\KwanfahArunrerk\Desktop\Sinwattana_repo\trunk\sinwattana3_0\campaign\models.py", line 5, in <module>
from sinUser.models import sinUser, sinUserCategories
File "C:\Users\KwanfahArunrerk\Desktop\Sinwattana_repo\trunk\sinwattana3_0\sinUser\models.py", line 4, in <module>
from functionUtility.sendEmails import sendEmailFunctionIsError
File "C:\Users\KwanfahArunrerk\Desktop\Sinwattana_repo\trunk\sinwattana3_0\functionUtility\sendEmails.py", line 12, in <module>
HOSTNAME = Site.objects.get_current().domain
File "C:\Python27\lib\site-packages\django\contrib\sites\models.py", line 63, in get_current
return self._get_site_by_id(site_id)
File "C:\Python27\lib\site-packages\django\contrib\sites\models.py", line 35, in _get_site_by_id
site = self.get(pk=site_id)
File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 374, in get
num = len(clone)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 232, in __len__
self._fetch_all()
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 1118, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py", line 894, in execute_sql
raise original_exception
django.db.utils.OperationalError: no such table: django_site
我是新手python编程
有些人可以帮助我谢谢
答案 0 :(得分:3)
您的sendEmails
模块在顶层有一个查询:Site.objects.get_current()
。在迁移有机会运行之前,在导入模块时运行。
您不得在此级别执行任何数据库操作;把它放进一个方法。
答案 1 :(得分:2)
在您的INSTALLED_APPS和运行迁移命令
中添加django.contrib.sites
python manage.py makemigrations
python manage.py migrate
希望这有助于你
答案 2 :(得分:1)
将"django.contrib.admin"
中的INSTALLED_APPS
更改为"django.contrib.admin.apps.SimpleAdminConfig"
,然后运行makemigrations
命令。之后,您可以还原更改。
答案 3 :(得分:0)
在这种情况下,某些迁移仍未完成,因此请运行python manage.py migrate
和python manage.py makemigrations app_name