在Django中重置SQLite数据库 [英] Reset SQLite database in Django

查看:169
本文介绍了在Django中重置SQLite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重构Django项目。我重命名了几个应用程序并添加了一个新的应用程序,还改组了一些模型。我想清除数据库和迁移并重新开始,但是我不确定如何做到这一点。这是我所做的:

I am trying to refactor a Django project. I renamed a couple apps and added a new one, as well as shuffled some models around. I want to clear my database and migrations and start fresh, but I am not sure how to accomplish this. Here's what I did:

rm -r myapp/migrations // I ran this for all my apps    
python manage.py flush
python manage.py makemigrations myapp // I ran this for all my apps
python manage.py migrate // This errors

我得到一个错误:

django.db.utils.OperationalError: table "myapp_mymodel" already exists

有人可以告诉我我可能做错了什么吗?

Can anyone tell me what I might be doing wrong?

编辑: django删除所有表的命令是什么?不起作用。

推荐答案

删除数据库并删除迁移文件(您的迁移目录中的 .py .pyc )应用程序(请勿删除 __ init __。py 文件)。然后运行 python manage.py makemigrations应用 python manage.py migration

Delete database and delete migration files (.py and .pyc) in migrations directory of your app (don't delete __init__.py file). Then run python manage.py makemigrations app and python manage.py migrate.

这篇关于在Django中重置SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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