🛠️ Step-by-step Migration Process
✅ 1. Install MySQL Driver
Inside my virtual environment:
pip install mysqlclient
(Alternatively, you can use pymysql if you face issues with mysqlclient.)
✅ 2. Create a New MySQL Database
Using MySQL Workbench or CLI:
CREATE DATABASE myproject_db CHARACTER SET UTF8MB4;
✅ 3. Update settings.py
I replaced the default SQLite configuration with MySQL:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'myproject_db',
'USER': 'root',
'PASSWORD': 'your_password',
'HOST': 'localhost',
'PORT': '3306',
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
},
}
}
✅ 4. Apply Migrations
python manage.py makemigrations
python manage.py migrate
✅ 5. Create a New Superuser
Since the database is clean, I recreated the admin user:
python manage.py createsuperuser
✅ 6. Test Functionality
All API endpoints were tested via Postman.
Admin panel access was verified.
Existing unit tests were re-run to confirm stability.
✅ 7. Optional: Migrate data from SQLite to MySQL
python manage.py dumpdata > data.json
# after switching DB
python manage.py loaddata data.json
🔗 My Work Online
🔹 Portfolio: https://nicolasandrescl.github.io/
🔹 GitHub Repo: https://github.com/NicolasAndresCL/API_con_DRF
💬 Final Thoughts
This migration helped me take my backend to the next level. Whether it's for performance, structure, or readiness for deployment, using MySQL brings me closer to a professional production setup.
Would love to hear your thoughts – which DB do you prefer for your Django projects?
Top comments (0)