如何使用Django中的manage.py CLI从数据库中删除所有表? [英] How to drop all tables from the database with manage.py CLI in Django?

查看:227
本文介绍了如何使用Django中的manage.py CLI从数据库中删除所有表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用manage.py和命令行从数据库中删除所有表?有没有办法使用适当的参数执行manage.py,所以我可以从.NET应用程序执行它?

How can I drop all tables from a database using manage.py and command line? Is there any way to do that executing manage.py with appropriate parameters so I can execute it from a .NET application?

推荐答案

据我所知,没有管理命令删除所有表。如果你不介意黑客Python,你可以编写自己的自定义命令来做到这一点。您可能会发现 sqlclear 选项有趣。文档说, ./ manage.py sqlclear 打印给定应用程序名称的DROP TABLE SQL语句。

As far as I know there is no management command to drop all tables. If you don't mind hacking Python you can write your own custom command to do that. You may find the sqlclear option interesting. Documentation says that ./manage.py sqlclear Prints the DROP TABLE SQL statements for the given app name(s).

更新
无耻地占用 @Mike DeSimone 在这个答案下面给出一个完整的答案。

Update: Shamelessly appropriating @Mike DeSimone's comment below this answer to give a complete answer.

./manage.py sqlclear | ./manage.py dbshell

这篇关于如何使用Django中的manage.py CLI从数据库中删除所有表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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