首页 > 其他 > 详细

django报错_admin历史

时间:2019-05-29 13:27:58      阅读:131      评论:0      收藏:0      [点我收藏+]

django 报错:django.db.utils.OperationalError: no such table: main.auth_user__old

在Djangotutorial 中,admin页面中修改后,查看 历史
时报错.
Django version:2.1 python version:3.7 这两种版本没有问题. 问题出在sqlite3 中.
参考: stackoverflow
中关于此问题的讨论,
成功的解决方案:
在 Lib\site-packages\django\db\backends\sqlite3\schema.py中,修改如下:

   def __enter__(self):
        # Some SQLite schema alterations need foreign key constraints to be
        # disabled. Enforce it here for the duration of the transaction.

        self.connection.disable_constraint_checking()
        self.connection.cursor().execute('PRAGMA foreign_keys = 0')  ## 自己加的
        self.connection.cursor().execute('PRAGMA legacy_alter_table = ON') # 自己加的
        return super().__enter__()

注意,修改后这个shcema.py并没有生效, 我把 db.sqlite3文件删除,在重新 python manage.py makemigrations,python manage.py migrate.
重新生成数据库文件后,OK.

django报错_admin历史

原文:https://www.cnblogs.com/ShawSpring/p/10943147.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!