You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将Django站点从MySQL切换至SQLite的问题求助

问题:Django切换到SQLite时触发SyntaxError错误

我正尝试将Django站点切换为使用SQLite(Django默认数据库),之前为了部署到GoDaddy平台改用了MySQL。我修改了settings.py中的DATABASES配置为SQLite默认设置:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

但执行python manage.py makemigrations命令时遇到如下错误:

(env) PS C:\Users\kayak\New Work\google athentication\mysite> python manage.py makemigrations 
Traceback (most recent call last):
  File "C:\Users\kayak\New Work\google athentication\mysite\manage.py", line 22, in <module>
    main()
  File "C:\Users\kayak\New Work\google athentication\mysite\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\django\core\management\__init__.py", line 386, in execute
    settings.INSTALLED_APPS
  File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\django\conf\__init__.py", line 92, in __getattr__
    self._setup(name)
  File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\django\conf\__init__.py", line 79, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\django\conf\__init__.py", line 190, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\Users\kayak\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\kayak\New Work\google athentication\mysite\mysite\settings.py", line 12, in <module>
    import heroku
  File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\heroku\__init__.py", line 27, in <module>
    from .core import from_key, get_key, from_pass
  File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\heroku\core.py", line 10, in <module>
    from .api import Heroku
  File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\heroku\api.py", line 11, in <module>
    from .helpers import is_collection
  
File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\heroku\helpers.py", line 57

    except TypeError, e:
           ^^^^^^^^^^^^
SyntaxError: multiple exception types must be parenthesized

解决方案

错误根源是heroku库使用了Python 2的语法(except TypeError, e:),而你当前使用的Python 3.10不兼容这种写法。更关键的是,切换到本地SQLite时根本不需要这个库,直接按以下步骤处理:

  1. 打开项目的mysite/settings.py文件,找到第12行的import heroku代码,删除该行
  2. 保存文件后,重新执行命令:
    python manage.py makemigrations
    python manage.py migrate
    

如果后续不需要部署到Heroku平台,也可以直接卸载这个过时的库:

pip uninstall heroku

内容的提问来源于stack exchange,提问作者False Flamingo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 02:25:17