如何从头开始删除Django 1.9中的DB(sqlite3)? [英] How do I delete DB (sqlite3) in Django 1.9 to start from scratch?

查看:287
本文介绍了如何从头开始删除Django 1.9中的DB(sqlite3)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模型中犯了一个拼写错误,现在我的一列被拼错了。我想删除数据库中的所有表,修复model.py中的错误,并使用模型中的正确拼写重新创建数据库。

I made a spelling error in my model and now one of my columns is misspelled. I'd like to drop all tables in the database, fix the error in the model.py, and recreate the database with the correct spelling in model.

尝试使用本文中的建议,但是按照我列出的命令操作后,表格仍然存在。

I've tried to use the suggestions in the this article but the table still exists after I follow the commands outlined there.

任何人都有快速的方法吗?

Anyone have a quick way to do this?

推荐答案


  1. 删除sqlite数据库文件(通常 db.sqlite3 )在django项目文件夹中(或放置在任何位置)

  2. 删除,除了 __ init __。py 所有django应用程序中 migration 文件夹中的文件

  3. 对模型进行更改( models.py )。

  4. 运行命令 python manage.py makemigrations python3 manage.py makemigration s

  5. 然后运行命令 python manage.py migration

  1. Delete the sqlite database file (often db.sqlite3) in your django project folder (or wherever you placed it)
  2. Delete everything except __init__.py file from migration folder in all django apps
  3. Make changes in your models (models.py).
  4. Run the command python manage.py makemigrations or python3 manage.py makemigrations
  5. Then run the command python manage.py migrate.

仅此而已。

如果未检测到对模型的更改 makemigrations 命令,请检查此答案

If your changes to the models are not detected by makemigrations command, please check this answer

这篇关于如何从头开始删除Django 1.9中的DB(sqlite3)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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