我试图连接我的Django应用程序与Mysql数据库,但当我试图迁移负载的错误开始弹出在终端。

2024-09-30 12:24:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试了各种方法(stackoverflow中提到的每个解决方案)来解决这个问题,但问题仍然在继续。你知道吗

当我跑的时候:“Python管理.pymigrate“显示以下错误

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/management/base.py", line 305, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/management/base.py", line 353, in execute
    self.check()
  File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/management/base.py", line 385, in check
    include_deployment_checks=include_deployment_checks,
  File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 61, in _run_checks
    issues = run_checks(tags=[Tags.database])
  File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/checks/database.py", line 9, in check_database_backends
    for conn in connections.all():
  File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/db/utils.py", line 226, in all
    return [self[alias] for alias in self]
  File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/db/utils.py", line 211, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/db/utils.py", line 115, in load_backend
    return import_module('%s.base' % backend_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 28, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

然后我试着按照stackoverflow中的建议:“pip install mysql python”提出类似的问题。我犯了以下错误

Collecting mysql-python
  Using cached MySQL-python-1.2.5.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/7_/cx21vvvn5cqdypfndc7j_jl80000gn/T/pip-build-JjMQeR/mysql-python/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 53, in get_config
        libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
      File "setup_posix.py", line 8, in dequote
        if s[0] in "\"'" and s[0] == s[-1]:
    IndexError: string index out of range

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/7_/cx21vvvn5cqdypfndc7j_jl80000gn/T/pip-build-JjMQeR/mysql-python/

我甚至尝试过:“brew install mysql-connector-c”,但同样的错误开始出现。你知道吗


Tags: djangoinpycorelibpackageslinesite
1条回答
网友
1楼 · 发布于 2024-09-30 12:24:49

我终于做到了: 首先,我安装了在virtualenv中运行以下代码所需的命令行开发工具

$ xcode-select  install

然后我使用以下代码安装MySQL-python

pip install MySQL-python

最后,我使用以下方法迁移了数据库:

python manage.py migrate

它没有任何错误 这个错误的主要问题是我没有安装所需的命令行开发工具。你知道吗

相关问题 更多 >

    热门问题