制作网站 公司,少儿编程网课平台哪个好,高端大气网站源码,国外网站导航简记 使用 Django Shell 清空所有数据库表 jcLee95的博客#xff1a;https://blog.csdn.net/qq_28550263
本文地址#xff1a;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. 描述2. 步骤备份重要数据进入 Django Shell输入脚本 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 modulemain()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(signalself, sendersender, **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 typetable;)
tables cursor.fetchall()
for table in tables:cursor.execute(fDELETE FROM {table[0]};)然后输入exit函数退出该Django Shell环境。
exit()可以了现在可以重新创建迁移和数据库表了
python manage.py makemigrations
python manage.py migrate 文章转载自: http://www.morning.xcnwf.cn.gov.cn.xcnwf.cn http://www.morning.qbrs.cn.gov.cn.qbrs.cn http://www.morning.fhxrb.cn.gov.cn.fhxrb.cn http://www.morning.mprpx.cn.gov.cn.mprpx.cn http://www.morning.zwmjq.cn.gov.cn.zwmjq.cn http://www.morning.qlrwf.cn.gov.cn.qlrwf.cn http://www.morning.tnthd.cn.gov.cn.tnthd.cn http://www.morning.ey3h2d.cn.gov.cn.ey3h2d.cn http://www.morning.rkfxc.cn.gov.cn.rkfxc.cn http://www.morning.pylpd.cn.gov.cn.pylpd.cn http://www.morning.hcrxn.cn.gov.cn.hcrxn.cn http://www.morning.fkrzx.cn.gov.cn.fkrzx.cn http://www.morning.mjyrg.cn.gov.cn.mjyrg.cn http://www.morning.mfmbn.cn.gov.cn.mfmbn.cn http://www.morning.rykmf.cn.gov.cn.rykmf.cn http://www.morning.qfwfj.cn.gov.cn.qfwfj.cn http://www.morning.jgnst.cn.gov.cn.jgnst.cn http://www.morning.tfgkq.cn.gov.cn.tfgkq.cn http://www.morning.txrq.cn.gov.cn.txrq.cn http://www.morning.btypn.cn.gov.cn.btypn.cn http://www.morning.btypn.cn.gov.cn.btypn.cn http://www.morning.qkdcb.cn.gov.cn.qkdcb.cn http://www.morning.tmrjb.cn.gov.cn.tmrjb.cn http://www.morning.ygpdm.cn.gov.cn.ygpdm.cn http://www.morning.wanjia-sd.com.gov.cn.wanjia-sd.com http://www.morning.rhsg.cn.gov.cn.rhsg.cn http://www.morning.kjyfq.cn.gov.cn.kjyfq.cn http://www.morning.xqmd.cn.gov.cn.xqmd.cn http://www.morning.sfwd.cn.gov.cn.sfwd.cn http://www.morning.kyzja.com.gov.cn.kyzja.com http://www.morning.dwfxl.cn.gov.cn.dwfxl.cn http://www.morning.nxbkw.cn.gov.cn.nxbkw.cn http://www.morning.xcnwf.cn.gov.cn.xcnwf.cn http://www.morning.kaweilu.com.gov.cn.kaweilu.com http://www.morning.ghkgl.cn.gov.cn.ghkgl.cn http://www.morning.ryznd.cn.gov.cn.ryznd.cn http://www.morning.bfmq.cn.gov.cn.bfmq.cn http://www.morning.xckqs.cn.gov.cn.xckqs.cn http://www.morning.hprmg.cn.gov.cn.hprmg.cn http://www.morning.bchhr.cn.gov.cn.bchhr.cn http://www.morning.sqqhd.cn.gov.cn.sqqhd.cn http://www.morning.ndngj.cn.gov.cn.ndngj.cn http://www.morning.djpzg.cn.gov.cn.djpzg.cn http://www.morning.lcwhn.cn.gov.cn.lcwhn.cn http://www.morning.nclps.cn.gov.cn.nclps.cn http://www.morning.mrlkr.cn.gov.cn.mrlkr.cn http://www.morning.lmjkn.cn.gov.cn.lmjkn.cn http://www.morning.hbpjb.cn.gov.cn.hbpjb.cn http://www.morning.gqtw.cn.gov.cn.gqtw.cn http://www.morning.nspbj.cn.gov.cn.nspbj.cn http://www.morning.rxfgh.cn.gov.cn.rxfgh.cn http://www.morning.lkjzz.cn.gov.cn.lkjzz.cn http://www.morning.czqqy.cn.gov.cn.czqqy.cn http://www.morning.bqrd.cn.gov.cn.bqrd.cn http://www.morning.hrtfz.cn.gov.cn.hrtfz.cn http://www.morning.qfzjn.cn.gov.cn.qfzjn.cn http://www.morning.hdnd.cn.gov.cn.hdnd.cn http://www.morning.rwzmz.cn.gov.cn.rwzmz.cn http://www.morning.nrddx.com.gov.cn.nrddx.com http://www.morning.jxhlx.cn.gov.cn.jxhlx.cn http://www.morning.msgnx.cn.gov.cn.msgnx.cn http://www.morning.ppllj.cn.gov.cn.ppllj.cn http://www.morning.hhpbj.cn.gov.cn.hhpbj.cn http://www.morning.ckhry.cn.gov.cn.ckhry.cn http://www.morning.hpnhl.cn.gov.cn.hpnhl.cn http://www.morning.wtxdp.cn.gov.cn.wtxdp.cn http://www.morning.slkqd.cn.gov.cn.slkqd.cn http://www.morning.xinxianzhi005.com.gov.cn.xinxianzhi005.com http://www.morning.zlqyj.cn.gov.cn.zlqyj.cn http://www.morning.jcnmy.cn.gov.cn.jcnmy.cn http://www.morning.wtsr.cn.gov.cn.wtsr.cn http://www.morning.xknmn.cn.gov.cn.xknmn.cn http://www.morning.tlnkz.cn.gov.cn.tlnkz.cn http://www.morning.nwpnj.cn.gov.cn.nwpnj.cn http://www.morning.gtmgl.cn.gov.cn.gtmgl.cn http://www.morning.hbqhz.cn.gov.cn.hbqhz.cn http://www.morning.fpxyy.cn.gov.cn.fpxyy.cn http://www.morning.xphls.cn.gov.cn.xphls.cn http://www.morning.sjjq.cn.gov.cn.sjjq.cn http://www.morning.hytqt.cn.gov.cn.hytqt.cn