Brahma Reddy
Brahma Reddy

Reputation: 25

operational error in django database connection

I have setup the MySQL database in django. but I am getting the operational error such as unknown database.

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    #'ENGINE': 'mysql.connector.django',
    'NAME': os.path.join(BASE_DIR, 'dbname'),
    'USER':'root',
    'PASSWORD':'********',
    'HOST':'localhost',
    'PORT':'3306',
}

}

But it throws following error:

django.db.utils.OperationalError: (1049, "Unknown database 'c:\users\brahmareddy\desktop\djangotable\checkingapp\djangodb'")

Upvotes: 0

Views: 392

Answers (2)

我要改名叫嘟嘟
我要改名叫嘟嘟

Reputation: 169

If you use docker, maybe you should check the docker volume.

docker volume --help
docker volume ls
docker volume  rm xx yy

Remove cache, restart.

Upvotes: 0

Anurag
Anurag

Reputation: 3114

your setting for mysql database should look like this

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': 'DB_NAME',
        'USER': 'DB_USER',
        'PASSWORD': 'DB_PASSWORD',
        'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
        'PORT': '3306',
    }
}

Name should not contain path, it is just the name of already running MySQL instance

Host is the IP Address of the MySQL server

Upvotes: 1

Related Questions