Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django.db.utils.OperationalError: (1046, 'No database selected')

Getting a strange error. I created a database in MySQL, set the database to use it. Using the right settings in my Django settings.py. But still there's an error that no database has been selected.

First I tried:

python manage.py syncdb

Got this traceback:

django.db.utils.OperationalError: (1046, 'No database selected')

settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'my_db',
        'USER': 'username',
        'PASSWORD': 'password',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}

What have I missed?

like image 803
lol5433 Avatar asked Dec 17 '15 21:12

lol5433


1 Answers

Check to make sure your database my_db exists in your MySQL instance. Log into MySQL and run;

show databases;

make sure my_db exists. If it does not, run

create database my_db;
like image 78
tornesi Avatar answered Oct 01 '22 16:10

tornesi