## **Preparatory Steps Before Using MySQL in Django**
### 1. Install Python and Django
* Make sure **Python** is installed.
* Install Django using pip:
```bash
pip install django
```
### 2. Create a Django Project
* Initialize your project folder:
```bash
django-admin startproject ProjectName
cd ProjectName
```
* This creates the main project structure, including `settings.py`, `urls.py`, and other files.
### 3. Create a Django App
* Apps are components of the project that handle specific functions:
```bash
python manage.py startapp AppName
```
* Add your app to `INSTALLED_APPS` in `settings.py`.
### 4. Test the Default Server
* Before connecting to MySQL, make sure Django is working with the default SQLite database:
```bash
python manage.py runserver
```
* Visit `http://127.0.0.1:8000/` to confirm the project is running.
### 5. Create Basic Models (Optional)
* You can create simple models to test migrations and app structure, even before MySQL.
```python
from django.db import models
class TestModel(models.Model):
name = models.CharField(max_length=50)
```
* This helps ensure your project structure and apps are ready.
### 6. Make Initial Migrations
* Run migrations using the default SQLite to ensure your models work:
```bash
python manage.py makemigrations
python manage.py migrate
```
* This step verifies your models are correct before switching to MySQL.
Ll
✅ **Summary:**
Before connecting to MySQL, you must:
1. Install Python and Django
2. Create a Django project
3. Create a Django app
4. Test the development server
5. Create basic models (optional but recommended)
6. Run initial migrations


0 comments:
Post a Comment