当前位置: 首页 > news >正文

什么网站备案容易审核花都定制型网站建设

什么网站备案容易审核,花都定制型网站建设,外贸人才网招聘网,郑州小学班级网站建设简记 使用 Django Shell 清空所有数据库表 jcLee95的博客:https://blog.csdn.net/qq_28550263 本文地址:https://blog.csdn.net/qq_28550263/article/details/132862795 目 录 1. 描述2. 步骤备份重要数据进入 Django Shell输入脚本 1. 描述 由于历史的…
简记
使用 Django Shell 清空所有数据库表

jcLee95的博客:https://blog.csdn.net/qq_28550263

本文地址:https://blog.csdn.net/qq_28550263/article/details/132862795



1. 描述

由于历史的迁移历史的混乱状态导致尝试运行 python manage.py migrate 时,Django 试图创建数据库表时发生了问题。错误信息中提到了缺少 django_content_type 表,这是Django用于跟踪模型的ContentType的表。

错误大致信息如下:

Operations to perform:Apply all migrations: admin, auth, contenttypes, sessions, users
Running migrations:No migrations to apply.
Traceback (most recent call last):File "C:\Python311\Lib\site-packages\django\db\backends\utils.py", line 89, in _executereturn self.cursor.execute(sql, params)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Python311\Lib\site-packages\django\db\backends\sqlite3\base.py", line 357, in executereturn Database.Cursor.execute(self, query, params)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: no such table: django_content_typeThe above exception was the direct cause of the following exception:Traceback (most recent call last):File "D:\desktop\jcmusic\manage.py", line 22, in <module>main()File "D:\desktop\jcmusic\manage.py", line 18, in mainexecute_from_command_line(sys.argv)File "C:\Python311\Lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_lineutility.execute()File "C:\Python311\Lib\site-packages\django\core\management\__init__.py", line 440, in executeself.fetch_command(subcommand).run_from_argv(self.argv)File "C:\Python311\Lib\site-packages\django\core\management\base.py", line 402, in run_from_argvself.execute(*args, **cmd_options)File "C:\Python311\Lib\site-packages\django\core\management\base.py", line 448, in executeoutput = self.handle(*args, **options)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Python311\Lib\site-packages\django\core\management\base.py", line 96, in wrappedres = handle_func(*args, **kwargs)^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Python311\Lib\site-packages\django\core\management\commands\migrate.py", line 376, in handleemit_post_migrate_signal(File "C:\Python311\Lib\site-packages\django\core\management\sql.py", line 52, in emit_post_migrate_signalmodels.signals.post_migrate.send(File "C:\Python311\Lib\site-packages\django\dispatch\dispatcher.py", line 176, in sendreturn [^File "C:\Python311\Lib\site-packages\django\dispatch\dispatcher.py", line 177, in <listcomp>(receiver, receiver(signal=self, sender=sender, **named))^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Python311\Lib\site-packages\django\contrib\auth\management\__init__.py", line 51, in create_permissionscreate_contenttypes(File "C:\Python311\Lib\site-packages\django\contrib\contenttypes\management\__init__.py", line 127, in create_contenttypescontent_types, app_models = get_contenttypes_and_models(^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Python311\Lib\site-packages\django\contrib\contenttypes\management\__init__.py", line 98, in get_contenttypes_and_modelscontent_types = {^File "C:\Python311\Lib\site-packages\django\db\models\query.py", line 394, in __iter__self._fetch_all()File "C:\Python311\Lib\site-packages\django\db\models\query.py", line 1867, in _fetch_allself._result_cache = list(self._iterable_class(self))^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Python311\Lib\site-packages\django\db\models\query.py", line 87, in __iter__results = compiler.execute_sql(^^^^^^^^^^^^^^^^^^^^^File "C:\Python311\Lib\site-packages\django\db\models\sql\compiler.py", line 1398, in execute_sqlcursor.execute(sql, params)File "C:\Python311\Lib\site-packages\django\db\backends\utils.py", line 102, in executereturn super().execute(sql, params)^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Python311\Lib\site-packages\django\db\backends\utils.py", line 67, in executereturn self._execute_with_wrappers(^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Python311\Lib\site-packages\django\db\backends\utils.py", line 80, in _execute_with_wrappersreturn executor(sql, params, many, context)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Python311\Lib\site-packages\django\db\backends\utils.py", line 84, in _executewith self.db.wrap_database_errors:File "C:\Python311\Lib\site-packages\django\db\utils.py", line 91, in __exit__raise dj_exc_value.with_traceback(traceback) from exc_valueFile "C:\Python311\Lib\site-packages\django\db\backends\utils.py", line 89, in _executereturn self.cursor.execute(sql, params)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Python311\Lib\site-packages\django\db\backends\sqlite3\base.py", line 357, in executereturn Database.Cursor.execute(self, query, params)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.OperationalError: no such table: django_content_type

我决定使用 Django Shell 清空数据库表。记录一下过程。

2. 步骤

备份重要数据

清理前,确保你使用各种手段备份过了所有重要数据,然后才清空数据库中的所有表。

进入 Django Shell

python manage.py shell

输入脚本

拷贝以下写好的删表脚本到交互式Shell中,键入回车开始执行。

from django.db import connection
cursor = connection.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()
for table in tables:cursor.execute(f"DELETE FROM {table[0]};")

然后输入exit函数退出该Django Shell环境。

exit()

可以了,现在可以重新创建迁移和数据库表了:

python manage.py makemigrations
python manage.py migrate
http://www.yayakq.cn/news/595100/

相关文章:

  • 欧美男女直接做的视频网站wordpress 模板 破解
  • 专业商城网站建设价格上海制作网页哪家好
  • 网站推广结束语wordpress网易云插件
  • 松原网站推广wordpress英文主题变中文版
  • 手机网站功能开发方案沭阳网站定制
  • 网站可不可以做自己的专利php网站 源码
  • 低价网站制作企业怎么样开发微信小程序
  • 网站建设常用软件jas全国icp备案查询
  • 山东省住房和城乡建设厅定额站子网站php 怎么做网站超链接
  • 电子商务网站建设作业文档wordpress增加下载功能
  • 郝友做的网站邯郸捕风科技有限公司
  • 开发外贸网站开发郑州seo顾问热狗hotdoger
  • 网站建设需要哪些网络技术网站中搜索关键词
  • 学网站开发月薪多少钱黄岩地区做环评立项在哪个网站
  • 淘宝这种网站怎么做的?营销型网站的建设步骤
  • 小程序开发外包服务合同南安seo教程
  • 网站建设内容规划凌云网最新消息
  • 大型网站的设计婚恋网站排名前十名
  • 做的很漂亮的网站上海网站建设 网页制作
  • 咖啡的网站建设策划书建设网站需要具备什么条件
  • 广州市网站建设 乾图信息科技做一个官方网站多少钱一个
  • 网站建设毕业设计题目海外网站域名注册
  • 网站流量来源哪个网站做螺丝生意好
  • 浙江省建设局城市平台网站wordpress文章不见
  • 网站建设氺首选金手指13长春软件开发
  • 上海建设工程造价网站网站首页优化
  • 动漫网站建设总结辽宁沈阳建设工程信息网
  • 朗读者外国人做的汉字网站中航鑫源建设集团有限公司网站
  • 网站怎么做成二维码做两个阿里网站吗
  • 网站 参数域名购买万网