Configure Django ORM with MySQL

Django uses sqlite as the default database. In this post, I’ll explain how to configure Django settings to connect with MySQL Database


  • Install Django
  • Install MySQL
  • Install mysqlclient

Configure file

In file under the project folder, change the DATABASES configuration.

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': "db_name",
        'USER': 'user',
        'PASSWORD': "password",
        'HOST': "192.168.x.xx", #ip address of the mysql
        "PORT": "3306" #default is 3306

Create Initial Migrations

Migrate initial django tables to the database, run

python makemigrations
python migrate

   Reprint policy

《Configure Django ORM with MySQL》 by Isaac Zhou is licensed under a Creative Commons Attribution 4.0 International License