How to drop all tables from the database with manage.py CLI in Django?(如何在 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 1.9 开始,它现在是 ./manage.py sqlflush
As of django 1.9 it's now ./manage.py sqlflush
这篇关于如何在 Django 中使用 manage.py CLI 从数据库中删除所有表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Django 中使用 manage.py CLI 从数据库中删除所有表?
基础教程推荐
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
