Django+Postgres: “current transaction is aborted, commands ignored until end of transaction block”

后端 未结 9 1473
暖寄归人
暖寄归人 2020-12-12 11:39

I\'ve started working on a Django/Postgres site. Sometimes I work in manage.py shell, and accidentally do some DB action that results in an error. Then I am una

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-12 11:58

    I add the following to my settings file, because I like the autocommit feature when I'm "playing around" but dont want it active when my site is running otherwise.

    So to get autocommit just in shell, I do this little hack:

    import sys
    if 'shell' in sys.argv or sys.argv[0].endswith('pydevconsole.py'):
        DATABASES['default']['OPTIONS']['autocommit'] = True
    

    NOTE: That second part is just because I work in PyCharm, which doesnt directly run manage.py

提交回复
热议问题