无法在Django中删除数据库并重新应用迁移?
在编写应用程序的过程中,我多次不得不删除数据库并重新运行迁移。这通常只需删除数据库文件,然后运行无法在Django中删除数据库并重新应用迁移?,django,django-models,django-migrations,django-database,Django,Django Models,Django Migrations,Django Database,在编写应用程序的过程中,我多次不得不删除数据库并重新运行迁移。这通常只需删除数据库文件,然后运行manage.py migrate。但是现在当我尝试这样做时,我得到一个错误,说django.db.utils.OperationalError:没有这样的表:Planner\u course,其中Planner是我的应用程序名,course是我的类模式之一。基本上我在做什么。我不确定为什么不到一周前我能用这个方法重置我的数据库,而现在我不能。有人有什么想法吗?无论是运行makemigrationsm
manage.py migrate
。但是现在当我尝试这样做时,我得到一个错误,说django.db.utils.OperationalError:没有这样的表:Planner\u course
,其中Planner是我的应用程序名,course是我的类模式之一。基本上我在做什么。我不确定为什么不到一周前我能用这个方法重置我的数据库,而现在我不能。有人有什么想法吗?无论是运行makemigrations
migrate
还是运行runserver
,我都会遇到错误,因为每当我重新运行没有db的迁移时,它都会简单地重新生成db并应用迁移。以下是完整的错误代码:
"C:\Program Files\JetBrains\PyCharm 2019.3.3\bin\runnerw64.exe" C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\python.exe "C:\Program Files\JetBrains\PyCharm 2019.3.3\plugins\python\helpers\pycharm\django_manage.py" migrate C:/Users/cabra/OneDrive/Desktop/CoursePlanner
Tracking file by folder pattern: migrations
Traceback (most recent call last):
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\base.py", line 396, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: Planner_course
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2019.3.3\plugins\python\helpers\pycharm\django_manage.py", line 52, in <module>
run_command()
File "C:\Program Files\JetBrains\PyCharm 2019.3.3\plugins\python\helpers\pycharm\django_manage.py", line 46, in run_command
run_module(manage_file, None, '__main__', True)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 206, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 96, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:/Users/cabra/OneDrive/Desktop/CoursePlanner\manage.py", line 21, in <module>
main()
File "C:/Users/cabra/OneDrive/Desktop/CoursePlanner\manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 366, in execute
self.check()
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = self._run_checks(
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\migrate.py", line 64, in _run_checks
issues.extend(super()._run_checks(**kwargs))
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 382, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\urls\resolvers.py", line 407, in check
for pattern in self.url_patterns:
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\urls\resolvers.py", line 588, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\urls\resolvers.py", line 581, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:/Users/cabra/OneDrive/Desktop/CoursePlanner\CoursePlanner\urls.py", line 21, in <module>
path('', include('Planner.urls'))
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:/Users/cabra/OneDrive/Desktop/CoursePlanner\Planner\urls.py", line 2, in <module>
from . import views
File "C:/Users/cabra/OneDrive/Desktop/CoursePlanner\Planner\views.py", line 15, in <module>
for course in courses:
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\query.py", line 276, in __iter__
self._fetch_all()
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\query.py", line 1261, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\query.py", line 57, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\sql\compiler.py", line 1144, in execute_sql
cursor.execute(sql, params)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\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:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\base.py", line 396, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: Planner_course
Process finished with exit code 1
“C:\Program Files\JetBrains\PyCharm 2019.3.3\bin\runnerw64.exe”C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\Python.exe“C:\Program Files\JetBrains\PyCharm 2019.3.3\plugins\Python\helpers\PyCharm\django\u manage.py”迁移C:/Users/cabra/OneDrive/Desktop/CoursePlanner
按文件夹模式跟踪文件:迁移
回溯(最近一次呼叫最后一次):
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\db\backends\utils.py”,第86行,在\u execute中
返回self.cursor.execute(sql,params)
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\db\backends\sqlite3\base.py”,第396行,在execute中
返回Database.Cursor.execute(self、query、params)
sqlite3.0错误:没有这样的表:Planner\u课程
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“C:\Program Files\JetBrains\PyCharm 2019.3.3\plugins\python\helpers\PyCharm\django_manage.py”,第52行,在
运行_命令()
文件“C:\Program Files\JetBrains\PyCharm 2019.3.3\plugins\python\helpers\PyCharm\django\u manage.py”,第46行,在run\u命令中
运行\u模块(管理\u文件,无,'.\u主\u',真)
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\runpy.py”,第206行,在run\u模块中
返回\u运行\u模块\u代码(代码、初始化全局、运行\u名称、模块规格)
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\runpy.py”,第96行,在运行模块代码中
_运行代码(代码、mod_globals、init_globals、,
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\runpy.py”,第86行,在运行代码中
exec(代码、运行\全局)
文件“C:/Users/cabra/OneDrive/Desktop/courseplan\manage.py”,第21行,在
main()
文件“C:/Users/cabra/OneDrive/Desktop/courseplan\manage.py”,第17行,主目录
从命令行(sys.argv)执行命令
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\core\management\\uuuuuuuu init\uuuuuuuuu.py”,第401行,从命令行执行
utility.execute()
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\core\management\\ uuuuuuu init\uuuuuuuu.py”,第395行,在execute中
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py”,第328行,从\u argv运行
self.execute(*args,**cmd_选项)
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\core\management\base.py”,第366行,在execute中
self.check()
检查文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\core\management\base.py”,第392行
所有问题=自我。运行检查(
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\core\management\commands\migrate.py”,第64行,在运行检查中
问题.扩展(超级().\u运行\u检查(**kwargs))
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\core\management\base.py”,第382行,在运行检查中
返回检查。运行检查(**kwargs)
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\core\checks\registry.py”,第72行,运行检查
新建错误=检查(应用程序配置=应用程序配置)
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\core\checks\url.py”,第13行,在check\u url\u config中
返回检查\u分解器(分解器)
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\core\checks\url.py”,第23行,在check\u解析器中
返回检查方法()
检查文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\url\resolvers.py”,第407行
对于self.url_模式中的模式:
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\utils\functional.py”,第48行,在__
res=instance.\uuuu dict\uuuu[self.name]=self.func(实例)
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\url\resolvers.py”,第588行,url\U模式
patterns=getattr(self.urlconf_模块,“urlpatterns”,self.urlconf_模块)
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\utils\functional.py”,第48行,在__
res=instance.\uuuu dict\uuuu[self.name]=self.func(实例)
urlconf_模块中的文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\site packages\django\url\resolvers.py”,第581行
返回导入_模块(self.urlconf_名称)
文件“C:\Users\cabra\AppData\Local\Programs\Python\Python38-32\lib\importlib\\uuuuuu init\uuuuuu.py”,第127行,在导入模块中
return _bootstrap._gcd_import(名称[级别:],包,级别)
文件“”,第1014行,在\u gcd\u导入中
文件“”,第991行,在“查找”和“加载”中
文件“”,第975行,在“查找”和“加载”中解锁
文件“”,第671行,在\u加载\u解锁
exec_模块中第783行的文件“”
文件“”,第219行,在“调用”中,删除了“帧”
文件“C:/Users/cabra/OneDrive/Desk