如何删除 django 中的数据库表?

2024-01-06

我改变了模型并进行了迁移。然后我又更改了一次模型,当尝试 python manage.py migrate 时出现错误:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions, shop
Running migrations:
  Applying shop.0004_auto_20180128_1331...Traceback (most recent call last):
  File "/home/morilon/dj/intshop/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
    return self.cursor.execute(sql)
  File "/home/morilon/dj/intshop/venv/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 301, in execute
    return Database.Cursor.execute(self, query)
sqlite3.OperationalError: table "shop_brand" already exists

所以我的问题是 - 我怎样才能删除表“shop_brand”??? 我已经尝试过了flush and sqlflush但这仅从表中删除数据,但实际上并未删除表“shop_brand”。

我使用 django 2.0.1 和 python 3.6


使用dbshel​​l命令

python manage.py dbshell

然后,在 shell 中,根据您使用的数据库,键入命令来显示表以标识要删除的表。

例如,对于 sqlite,您可以使用

.tables

仍然在 shell 中,您可以使用 SQL 命令删除表

DROP TABLE shop_brand;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何删除 django 中的数据库表? 的相关文章

随机推荐