我无法进入 django admin 中的帖子

I can not get into posts in django admin

一旦我点击 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

我不知道这段代码有什么问题

请通过此命令进入 Django shell

python manage.py shell

然后从模型文件导入模型并触发更新查询

问题在于,在 SQLite 中,日期只是存储为字符串,因此您可以存储任何无效日期,只要它是列中的字符串即可。但是使用的游标会尝试将这个日期转换成字符串,在这个级别你会得到一个错误。因此,您无法解决使用 ORM 来解决此问题,必须使用 SQL 查询来解决此问题。

如果您不知道如何打开数据库,您可以使用 Django 的 shell (python manage.py shell) 的原始查询 shell,下面的代码片段假定您的应用是名为 test_app,您需要将其替换为您自己的应用程序名称:

from django.db import connection


with connection.cursor() as cursor:
    cursor.execute("UPDATE test_app_post SET flight_date='2021-05-27' WHERE flight_date='27th June'")