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 从数据库中删除所有表?
基础教程推荐
- 是否可以执行按位分组功能? 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 无法解决整理冲突 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
