Django没有这样的表:删除迁移和数据库后的django_site [英] Django no such table: django_site after deleting migrations and database

查看:69
本文介绍了Django没有这样的表:删除迁移和数据库后的django_site的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图更改应用名称。这没有用,所以我试图改回去。这也不起作用,我删除了所有迁移和db.sqlite。现在,每当我尝试 makemigrations migration 时,都会出现此错误:

I tried to change an app name. This didnt work and so I tried to change it back. This didnt work either and I deleted all migrations and my db.sqlite. Now whenever I try makemigrations or migrate I get this error:

django.db.utils.OperationalError: no such table: django_site

完全追溯:

Traceback (most recent call last):
  File "C:\Users\Myzel394\Documents\PROGRAMMIEREN\Schule\MGLZeitung\manage.py", line 18, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\base.py", line 350, in execute
    self.check()
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\base.py", line 379, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\base.py", line 366, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Program Files\Python37\lib\site-packages\django\core\checks\registry.py", line 71, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Program Files\Python37\lib\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "C:\Program Files\Python37\lib\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "C:\Program Files\Python37\lib\site-packages\django\utils\functional.py", line 37, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Program Files\Python37\lib\site-packages\django\urls\resolvers.py", line 533, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Program Files\Python37\lib\site-packages\django\utils\functional.py", line 37, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Program Files\Python37\lib\site-packages\django\urls\resolvers.py", line 526, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Program Files\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\Myzel394\Documents\PROGRAMMIEREN\Schule\MGLZeitung\MGLZeitung\urls.py", line 28, in <module>
    path('account/', include("apps.account.urls", namespace="account")),
  File "C:\Program Files\Python37\lib\site-packages\django\urls\conf.py", line 34, in include
    urlconf_module = import_module(urlconf_module)
  File "C:\Program Files\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\Myzel394\Documents\PROGRAMMIEREN\Schule\MGLZeitung\apps\account\urls.py", line 15, in <module>
    path('loeschen/fertig', TemplateView.as_view(template_name="account/account/delete_done.html", extra_context={'title': title_suffix("Account Gelöscht")}), name="delete_done")
  File "C:\Users\Myzel394\Documents\PROGRAMMIEREN\Schule\MGLZeitung\utils\urls.py", line 12, in title_suffix
    return URL_SUFFIX_ONE.format(title, " ".join(site_name()))
  File "C:\Users\Myzel394\Documents\PROGRAMMIEREN\Schule\MGLZeitung\apps\homepage\templatetags\utils.py", line 219, in site_name
    return Site.objects.all().first().name.split(" ")
  File "C:\Program Files\Python37\lib\site-packages\django\db\models\query.py", line 605, in first
    for obj in (self if self.ordered else self.order_by('pk'))[:1]:
  File "C:\Program Files\Python37\lib\site-packages\django\db\models\query.py", line 268, in __iter__
    self._fetch_all()
  File "C:\Program Files\Python37\lib\site-packages\django\db\models\query.py", line 1186, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "C:\Program Files\Python37\lib\site-packages\django\db\models\query.py", line 54, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "C:\Program Files\Python37\lib\site-packages\django\db\models\sql\compiler.py", line 1065, in execute_sql
    cursor.execute(sql, params)
  File "C:\Program Files\Python37\lib\site-packages\django\db\backends\utils.py", line 100, in execute
    return super().execute(sql, params)
  File "C:\Program Files\Python37\lib\site-packages\django\db\backends\utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "C:\Program Files\Python37\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:\Program Files\Python37\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Program Files\Python37\lib\site-packages\django\db\utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Program Files\Python37\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Program Files\Python37\lib\site-packages\django\db\backends\sqlite3\base.py", line 298, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: django_site

我尝试了这些答案,但它们并没有帮助我:没有django_site 这样的表,Django 1.5.4:无此类表:admin / 中的django_site

I tried these answers but they didnt help me: No such table as django_site, Django 1.5.4: no such table: django_site in admin/

我真的不知道该怎么办。也许有人可以帮我。

I really dont know what to do. Maybe someone can help me.

推荐答案

删除 django.contrib.sites 从您的 installed_apps settings.py

然后运行:

python manage.py makemigrations
python manage.py migrate

django.contrib.sites 添加到您的 installed_apps 并运行:

python manage.py makemigrations
python manage.py migrate

应该这样做。

这篇关于Django没有这样的表:删除迁移和数据库后的django_site的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆