Django MySQL Database Connection Example

This is our eleventh article in Django, in this article we are going to learn about Django MySQL Database Connection Example. so as you know django comes with default setting for SQLite database, but you can change that and you can add your favorite database, particularly in this article we are going to use MySQL Database, also for this purpose we are using a virtual server called WAMP Server.

 

 

 

Flask Web Development Tutorials

1: Flask CRUD Application with SQLAlchemy 

2: Flask Creating News Web Application 

3: Flask Creating REST API with Marshmallow 

 

 

 

Python GUI Development Tutorials

1: PyQt5 GUI Development Tutorials

2: Pyside2 GUI Development Tutorials

3: wxPython GUI Development Tutorials

4: Kivy GUI Development Tutorials 

5: TKinter GUI Development Tutorials 

 

 

What is MySQL Database ?

MySQL is an open-source relational database management system. Its name is a combination of “My”, the name of co-founder Michael Widenius’s daughter, and “SQL”, the abbreviation for Structured Query Language.

 

 

 

 

OK first of all you need to create a project in Django, we have already covered the creation of the Django project in our previous article Django Introduction & Installation. but you can use this command for creating of Django Project.

 

 

 

Now you need to create a database in the WAMP Server, so my Database name is codeloop. but you can give what ever you want for the database name.

 

As we have created our Django Project, now we need to open settings.py file in Django Project and bring some changes in the DATABASE section, by default if you see we have SQLite3 database. but we want to use MySQL Database. for this purpose you need to add some configuration of your mysql database, for example like database name,  port, username, password and database host.

 

 

 

After adding these configurations in your settings.py file, you need to migrate your project, because we have added a new database configuration.

 

 

 

 

After doing migrate, you will see this result in your terminal.

 

 

 

 

Now if you check your WAMP Server mysql database, you will see the migrations file in your mysql database.

Django MySQL Database Connection Example
Django MySQL Database Connection Example

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×