skip to Main Content

I’m trying to do python manage.py migrate on a cPanel but I keep getting TypeError: 'staticmethod' object is not callable.

makemigations and collectstatic work fine.

I’ve attempted to fix this by installing WhiteNoise but it didn’t work.

When I set DEBUG=True it uses SQLite and migrate does work so I’m guessing it’s got something to do with MySQL?

In base.py I have:


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/"

in urls.py I have:

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)),
    ]

I printed them in production (in the cPanel) and path to each looks correct.

Not sure if this help but navigating to the domain gives me the error:

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'.

Nothing gets logged in instderr.log

Full Traceback

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

My manage.py file:

#!/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)

My base.py is located under mysite -> settings -> base.py

2

Answers


  1. Chosen as BEST ANSWER

    The solution to the problem is to use django.db.backends.mysql instead of mysql.connector.django.

    I also had to add 'OPTIONS': {'charset': 'utf8mb4'} to solve the error "Illegal mix of collations (utf8mb3_unicode_ci,IMPLICIT) and (utf8mb3_general_ci,IMPLICIT) for operation '='")

    DATABASES = {
        'default': {
            'ENGINE':'django.db.backends.mysql',
            'NAME': env('PRODUCTION_DATABASE_NAME'),
            'USER': env('PRODUCTION_DATABASE_USERNAME'),
            'PASSWORD': env('PRODUCTION_DATABASE_PASSWORD'),
            'HOST': env('PRODUCTION_DATABASE_HOST'),
            'OPTIONS': {'charset': 'utf8mb4'},
        }
    }
    
    

    In addition, I had to pip install pymysql and add the below code into __init__.py located in my settings folder (same folder as base.py)

    import pymysql
    
    pymysql.install_as_MySQLdb()
    

  2. I understand the answer has been checked, but for the sake of anyone out there that might be hitting their head against the wall like I was.

    The solution works but with few modifications now…

    import pymysql
    pymysql.version_info = (1, 4, 6, 'final', 0)
    pymysql.install_as_MySQLdb()
    

    You need to specify the version else you’ll get a version error. After this you might still get an error of MariaDB version. Finally downgrade your Django version to 4.0

    pip uninstall django
    pip install django==4.0
    

    Then make sure to refresh your terminal.
    You should be good to go!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search