TypeError: DatabaseWrapper.display_name() takes 0 positional arguments but 1 was given

326 views Asked by At

I am getting the following error when running "python manage.py migrate" in cpanel terminal. I am using mysql for database. The library that I am using is mysql-connector-python.

TypeError: DatabaseWrapper.display_name() takes 0 positional arguments but 1 was given

The following are the settings of my settings file:

DATABASES = {
    "default": {
        "ENGINE": "mysql.connector.django",
        "NAME": "my-database-name",
        "HOST": "localhost",
        "PORT": "3306",
        "USER": "my-database-username",
        "PASSWORD": "my-password",
    }
}
2

There are 2 answers

1
Ser obiri On

the code should be this way

DATABASES = {
    "default": {
        "ENGINE": "mysql.connector.django",
        "NAME": "my-database-name",
        "HOST": "localhost",
        "PORT": "3306",
        "USER": "my-database-username",
        "PASSWORD": "my-password",
         'OPTIONS': {'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" ,"use_pure": True},
          
    }
}

0
Huỳnh Khả Phi On

I guess you were using virtual environment. Use pymysql, it worked for me.

pip install pymysql

First, config settings.py with DATABASES like this

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': BASE_DIR / 'db.sqlite3',
},
'product': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'djangoStorage',
    'USER': 'root',
    'PASSWORD': '',
    'HOST': 'localhost',
    'PORT': 3306
}

}

And put on the top of manage.py and wsgi.py

import os
import sys
import pymysql
pymysql.install_as_MySQLdb()

And finally,

python manage.py makemigrations
python manage.py migrate --database:product