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 从数据库中删除所有表?


- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- SQL 临时表问题 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01