【发布时间】:2021-05-27 07:12:39
【问题描述】:
单击 django admin 中的帖子后,此消息会弹出 ValueError at /admin/blog/post/ 基数为 10 的 int() 的无效文字:b'27th June' 是的,我在 DateField 中输入了错误的数据形式。我想删除这些数据。这就是为什么我试图进入 django admin 中的帖子。有没有办法解决这个问题?
models.py
class Post(models.Model):
flight_date = models.DateField(blank=False)
我去了 django shell 并输入了这段代码,但得到了这个错误;
>>> from django.db import connection
>>> with connection.cursor() as cursor:
... cursor.execute("UPDATE blog_post SET flight_date='2021-05-27' WHERE flight_date='27th June'")
File "<console>", line 2
cursor.execute("UPDATE blog_post SET flight_date='2021-05-27' WHERE flight_date='27th June'")
^
IndentationError: expected an indented block
我不知道这段代码有什么问题
【问题讨论】:
-
您使用的是 SQLite(这只能在 SQLite 中实现)?您必须通过编写 SQL 手动删除它,就像您尝试使用 python 查询一样,您总是会收到错误。
标签: python django django-models django-admin