使用Django删除postgresql数据库中的所有表,而不删除数据库

2024-10-03 06:26:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在运行awslasticbeans,它自动为我设置一个工作的postgresql数据库实例和连接。因此,我不想只删除数据库实例并自己配置它。我宁愿从python/django中删除数据库中的所有表。我也不想删除所有表的内容(正如python manage.py flush所做的)。你知道吗

我希望数据库返回到一种状态,在这种状态下我可以运行python manage.py migrate,它将根据我当前的模型定义创建所有空表。你知道吗

谢谢


Tags: django实例py模型数据库内容定义manage
1条回答
网友
1楼 · 发布于 2024-10-03 06:26:04
# Prints the SQL statements that would be executed for the flush command. Will delete all the data from tables in database

django-admin sqlflush

# You can pass the name of your database specifically. Defaults to default.

 database DATABASE

# If you want to delete all the tables of your app, then you can run the command

python manage.py migrate appname zero

相关问题 更多 >