【问题标题】:Delete all tables in the postgresql database using Django without deleting the database [duplicate]使用Django删除postgresql数据库中的所有表而不删除数据库[重复]
【发布时间】:2020-04-18 19:31:37
【问题描述】:

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

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

谢谢

【问题讨论】:

  • @IainShelvington 是的,确实如此,谢谢

标签: python django postgresql amazon-web-services cloud


【解决方案1】:
# 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

【讨论】:

  • 我不想从表中删除所有数据,我想删除表本身,这样我就可以运行一个新的 python manage.py migrate 来用我的新表获得干净的表(也许更改)模型。
  • python manage.py migrate appname zero - 命令将删除您的表
猜你喜欢
  • 2010-11-27
  • 1970-01-01
  • 2011-03-20
  • 2014-07-29
  • 1970-01-01
  • 2023-03-30
  • 2013-07-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多