Django 1.6 : MySQL ERROR 1049 (42000): Unknown database
Question: According to the django tutorial on its official website, django creates
database schema according to the model defined in the `models.py`. But the
default engine for database is `sqlite3`. And it is working.

now when I installed the `mysql` and `Mysql Connector` for django and I tried
to create a database I encountered with the following error:

    
    
     mysql.connector.errors.ProgrammingError: 1049 (42000): Unknown database 'db.mysql.userdb'
    

I searched the error and found some solutions to this problem but all of them
mentioned that I have to create the database myself using `MYSQL Shell`. But
this is not what I want! According to the django website, I have to just
define my model and django creates the schema of database! _How can I do
that?_

Thanks in advance.

The following is my `sttings.py` file:

    
    
    # -*- coding: utf-8 -*-
    from __future__ import unicode_literals
    import os
    
    BASE_DIR = os.path.dirname(os.path.dirname(__file__))      
    
    SECRET_KEY = '94sf3cp(#a^)9!^zrr^zr3dfdk0nz$*4=m#v19*v)j&q^o$#ym'
    
    DEBUG = True
    
    TEMPLATE_DEBUG = True
    
    ALLOWED_HOSTS = []
    
    INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'website_user',
    )
    
    MIDDLEWARE_CLASSES = (
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
    )
    
    ROOT_URLCONF = 'Final_DBMI.urls'
    
    WSGI_APPLICATION = 'Final_DBMI.wsgi.application'
    
    
    DATABASES = {
        'default': {
            'ENGINE': 'mysql.connector.django',
            'NAME': 'db.mysql.userdb',
            'USER': 'hadi',
            'PASSWORD': '123456',
            'HOST': '127.0.0.1',
            'PORT': '3306'
        }
    }
    
    LANGUAGE_CODE = 'en-us'
    
    TIME_ZONE = 'UTC'
    
    USE_I18N = True
    
    USE_L10N = True
    
    USE_TZ = True       
    
    STATIC_URL = '/statics/'
    

**Update** I'm using this
[doc](https://docs.djangoproject.com/en/dev/ref/databases/) and according to
that there is two ways to connect to mysql:

  * MYSQLdb
  * MySQL Connector/Python

and I'm using the second one. According to the [MYSQL
website](http://dev.mysql.com/doc/connector-python/en/connector-python-django-
backend.html) it should be added to `settings.py` in the following way:

    
    
    DATABASES = {
        'default': {
            'NAME': 'user_data',
            'ENGINE': 'mysql.connector.django',
            'USER': 'mysql_user',
            'PASSWORD': 'priv4te',
            'OPTIONS': {
              'autocommit': True,
            },
        }
    }
    


Answer: Django creates the _tables_. It does not create the _database_ that the tables
live in; you must do that.

