我尝试在cPanel上执行python manage.py migrate
,但总是得到TypeError: 'staticmethod' object is not callable
。makemigations
和collectstatic
工作正常。
我试图通过安装WhiteNoise来解决这个问题,但它不起作用。
当我设置DEBUG=True时,它使用SQLite,并且迁移工作,所以我猜它与MySQL有关?
在www.example.com中base.py我有:
DATABASES = {
'default': {
'ENGINE':'mysql.connector.django',
'NAME': env('PRODUCTION_DATABASE_NAME'),
'USER': env('PRODUCTION_DATABASE_USERNAME'),
'PASSWORD': env('PRODUCTION_DATABASE_PASSWORD'),
'HOST': env('PRODUCTION_DATABASE_HOST')
}
}
STATICFILES_DIRS = [
os.path.join(PROJECT_DIR, "static"),
]
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = "/static/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"
在urls.py我有:
urlpatterns = [
re_path(r'^images/([^/]*)/(\d*)/([^/]*)/[^/]*$', ServeView.as_view(), name='wagtailimages_serve'),
path('tz_detect/', include('tz_detect.urls')),
# path("django-admin/", admin.site.urls),
path("admin/", include(wagtailadmin_urls)),
path("documents/", include(wagtaildocs_urls)),
path(r'sitemap.xml', sitemap),
path('robots.txt', RobotsView.as_view())
]
if settings.DEBUG:
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# Serve static and media files from development server
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns = urlpatterns + [
path('__debug__/', include('debug_toolbar.urls')),
path("", include(wagtail_urls)),
]
我在生产中打印了它们(在cPanel中),每个路径看起来都是正确的。
不知道这个帮助,但导航到域给我的错误:
Request Timeout
This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact administrator of this web site to increase 'Connection Timeout'.
instderr.log
中未记录任何内容
全面追溯
Traceback (most recent call last):
File "/home/user2/dev.mysite.com/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/user2/virtualenv/dev.mysite.com/3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/home/user2/virtualenv/dev.mysite.com/3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/user2/virtualenv/dev.mysite.com/3.9/lib/python3.9/site-packages/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/user2/virtualenv/dev.mysite.com/3.9/lib/python3.9/site-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
File "/home/user2/virtualenv/dev.mysite.com/3.9/lib/python3.9/site-packages/django/core/management/base.py", line 96, in wrapped
res = handle_func(*args, **kwargs)
File "/home/user2/virtualenv/dev.mysite.com/3.9/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 97, in handle
self.check(databases=[database])
File "/home/user2/virtualenv/dev.mysite.com/3.9/lib/python3.9/site-packages/django/core/management/base.py", line 475, in check
all_issues = checks.run_checks(
File "/home/user2/virtualenv/dev.mysite.com/3.9/lib/python3.9/site-packages/django/core/checks/registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/home/user2/virtualenv/dev.mysite.com/3.9/lib/python3.9/site-packages/django/core/checks/model_checks.py", line 36, in check_all_models
errors.extend(model.check(**kwargs))
File "/home/user2/virtualenv/dev.mysite.com/3.9/lib/python3.9/site-packages/django/db/models/base.py", line 1538, in check
*cls._check_constraints(databases),
File "/home/user2/virtualenv/dev.mysite.com/3.9/lib/python3.9/site-packages/django/db/models/base.py", line 2276, in _check_constraints
"conditions." % connection.display_name,
File "/home/user2/virtualenv/dev.mysite.com/3.9/lib/python3.9/site-packages/django/utils/functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
TypeError: 'staticmethod' object is not callable
我的manage.py文件:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings.base")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
我的base.py位于mysite -> settings -> base.py
下
1条答案
按热度按时间zour9fqk1#
问题的解决方案是使用
django.db.backends.mysql
而不是mysql.connector.django
。我还必须添加
'OPTIONS': {'charset': 'utf8mb4'}
来解决错误"Illegal mix of collations (utf8mb3_unicode_ci,IMPLICIT) and (utf8mb3_general_ci,IMPLICIT) for operation '='")
此外,我必须
pip install pymysql
并将下面的代码添加到位于我的设置文件夹(与www.example.com相同的文件夹)中的__init__.py
base.py中