Sunday, August 16, 2020

Django & Connecting it to MySQL

Connection to MySQL Database was a bit challenging task for me.


Background:

I started my Django experience with connection to the default database which is extremely light weight i.e. SQLite. This database gets locked at connecting to it more than once.

In my situation, the db got locked when I was trying to access it from a DB browser while having the Django server running. 

To make things more dynamic and to learn MySQL I began mulling on the idea to setup it up along with Django. 

Now back to the problem.
You primarily have to deal with setting.py under your base directory (BASE_DIR). 

In settings.py file of the Django Project, replace the sqlite3 engine with mysql engine as shown below.



Below given is the reference to mysql engine.


[Note: If you are migrating to MySQL after building the project with any other database, ensure that the migration folder under the apps are deleted.]

References are mentioned below. 

[Originally drafted on 6th August 2018]