Adding MySQL Databse to django project 

Database Config
MySQL Config Tejas Sawant

Step 1:- 

Start you database and create shema. In this example i am going to create ecom database.

CREATE SCHEMA `ecom` ;

Step 2:-

Installing mysqlclient using pip. For mysql drivers.

pip install mysqlclient

Step 3:-
Go to Django project. Then settings.py. Then we are going to write code for creating connectionEnter following code :- 

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'OPTIONS': {
            'read_default_file': 'mysql.cnf',
        },
    }
}

Step 4:-
We need to create mysql.cnf file in root directory. 

Need to enter following code in mysql.cnf file.

[client]
database = ecom # Databse Name.
user = root # Username for database.
password = 1122 # Password For Database.
port = 3306 # Your port number default is 3306.
default-character-set = utf8 # Leave it as default.

Once you run server. You can see following output.

Step 5:-

Migrating databse. For that you can use following command.

python manage.py migrate

This will migrate databse.

We have successfully connected Django with mysql databse.

Comments