Mysqldb将django站点复制到新服务器的问题

时间:2018-04-10 02:54:28

标签: python mysql django

我被困住了。我正在尝试在第二台服务器上复制我的fedora设置。我有问题。我的环境: - mysql(mariadb) - python3 - django - 使用mod_wsgi的apache

我收到500内部服务器错误。当我放大httpd error_log时,我看到了:

    [Mon Apr 09 22:44:14.119939 2018] [wsgi:error] [pid 2728:tid 140190313469696] [client 192.168.1.123:52304] mod_wsgi (pid=2728): Exception occurred processing WSGI script '/var/www/html/at/at/wsgi.py'.
[Mon Apr 09 22:44:14.120097 2018] [wsgi:error] [pid 2728:tid 140190313469696] [client 192.168.1.123:52304] Traceback (most recent call last):
[Mon Apr 09 22:44:14.120178 2018] [wsgi:error] [pid 2728:tid 140190313469696] [client 192.168.1.123:52304]   File "/var/www/html/at/at/wsgi.py", line 16, in <module>
[Mon Apr 09 22:44:14.120190 2018] [wsgi:error] [pid 2728:tid 140190313469696] [client 192.168.1.123:52304]     application = get_wsgi_application()
[Mon Apr 09 22:44:14.120206 2018] [wsgi:error] [pid 2728:tid 140190313469696] [client 192.168.1.123:52304]   File "/usr/local/lib64/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Mon Apr 09 22:44:14.120214 2018] [wsgi:error] [pid 2728:tid 140190313469696] [client 192.168.1.123:52304]     django.setup(set_prefix=False)
[Mon Apr 09 22:44:14.120228 2018] [wsgi:error] [pid 2728:tid 140190313469696] [client 192.168.1.123:52304]   File "/usr/local/lib64/python3.6/site-packages/django/__init__.py", line 24, in setup
[Mon Apr 09 22:44:14.120236 2018] [wsgi:error] [pid 2728:tid 140190313469696] [client 192.168.1.123:52304]     apps.populate(settings.INSTALLED_APPS)
[Mon Apr 09 22:44:14.120250 2018] [wsgi:error] [pid 2728:tid 140190313469696] [client 192.168.1.123:52304]   File "/usr/local/lib64/python3.6/site-packages/django/apps/registry.py", line 81, in populate
[Mon Apr 09 22:44:14.120258 2018] [wsgi:error] [pid 2728:tid 140190313469696] [client 192.168.1.123:52304]     raise RuntimeError("populate() isn't reentrant")
[Mon Apr 09 22:44:14.120285 2018] [wsgi:error] [pid 2728:tid 140190313469696] [client 192.168.1.123:52304] RuntimeError: populate() isn't reentrant

当我尝试运行python3 manage.py时,我收到以下错误 - 它看起来像是在与数据库交谈时遇到问题?我已经在mysql中创建了数据库并从mysqldump上传了内容。所以我没有遇到问题。我也安装了mysql-python,我认为是什么让我得到python3-mysql连接。

以下是我尝试python3 manage.py时的抱怨:

Traceback (most recent call last):
  File "/usr/local/lib64/python3.6/site-packages/django/db/backends/mysql/base.py", line 15, in <module>
    import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib64/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib64/python3.6/site-packages/django/core/management/__init__.py", line 347, in execute
    django.setup()
  File "/usr/local/lib64/python3.6/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib64/python3.6/site-packages/django/apps/registry.py", line 112, in populate
    app_config.import_models()
  File "/usr/local/lib64/python3.6/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/local/lib64/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/usr/local/lib64/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
    class AbstractBaseUser(models.Model):
  File "/usr/local/lib64/python3.6/site-packages/django/db/models/base.py", line 114, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "/usr/local/lib64/python3.6/site-packages/django/db/models/base.py", line 315, in add_to_class
    value.contribute_to_class(cls, name)
  File "/usr/local/lib64/python3.6/site-packages/django/db/models/options.py", line 205, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/usr/local/lib64/python3.6/site-packages/django/db/__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/usr/local/lib64/python3.6/site-packages/django/db/utils.py", line 202, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/usr/local/lib64/python3.6/site-packages/django/db/utils.py", line 110, in load_backend
    return import_module('%s.base' % backend_name)
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/local/lib64/python3.6/site-packages/django/db/backends/mysql/base.py", line 20, in <module>
    ) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?

你们可以提供给我的任何线索都会有所帮助。我发现重现我的生产服务器非常困难。 (有点遗憾做django的事情。)

最佳

汤姆

1 个答案:

答案 0 :(得分:0)

对于可能遇到此问题的其他人,让我解释一下我发现的内容:

我的网站写的是PRE DJANGO 2.0,经过很多搜索,我终于得到了答案。问题不在于已安装的连接器或包装 - 它们都很好。问题是在Django 2.0中,外部函数现在必须指定一个on_delete动作!所以你需要看起来像这样的东西:

你的models.py中的

(检查每一个是否为ForeignKey)。必须采用以下形式:

heading = models.ForeignKey(ForumSections, on_delete=models.CASCADE)

还有其他选择,但如果您没有从2.0开始的on_delete部分,您将看到我正在努力解决的错误。

祝你们好运。

干杯, 托米