M
M
Mike2017-06-25 21:56:13
Django
Mike, 2017-06-25 21:56:13

Why am I getting django.db.utils.InternalError: (1049, "Unknown database 'db'")?

I have this:

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

then I run python manage.py migrate and get this:
django.db.utils.InternalError: (1049, "Unknown database 'mydb'") ?

If you create a database via mysql in the console, then it works, but the database is created in /var/lib/mysql
How can I make the database be created at the root of the project?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2017-06-25
@fox_12

You are confusing mysql and sqllite databases.

A
Adikjoro, 2017-06-26
@Adikjoro

In "NAME" you write the name of the database that you created in the MySQL server.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mydb',
        'USER': 'root',
        'PASSWORD': 'password',
    }
}

When connecting to a local database, there is no need to specify the host and port.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question