Home > Enterprise >  error when trying to execute python manage.py migrate
error when trying to execute python manage.py migrate

Time:09-16

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

I get the above error when I try to execute:

python manage.py migrate

The database settings in my settings.py file are:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'DATABASE': 'financeblog',
        'USER': 'financeblog',
        'PASSWORD': 'xxxxx',
        'HOST': '127.0.0.1',
        'PORT': '3308',
    }
}

I have confirmed that the database does in fact exist. The port is 3308

CodePudding user response:

The key for the name of the database is NAME (not DATABASE). So you should do this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'financeblog',  # Change this
        'USER': 'financeblog',
        'PASSWORD': 'xxxxx',
        'HOST': '127.0.0.1',
        'PORT': '3308',
    }
}

And make sure, to install the mysqlclient python adapter too.

CodePudding user response:

The keyword DATABASE in settings.py is wrong. Should be NAME

  • Related