# Physicians Database Table Migration Fix ## Issue **Error:** `OperationalError: no such table: physicians_physicianindividualrating` **URL:** `/api/physicians/individual-ratings/` **Timestamp:** February 21, 2026 ## Root Cause The `physicians_physicianindividualrating` table did not exist in the database because the migration for the physicians app had not been applied. ## Analysis - The model `PhysicianIndividualRating` was defined in `apps/physicians/models.py` - Migration files existed: - `0001_initial.py` - `0002_doctorratingimportjob_physicianindividualrating.py` - These migrations had not been applied to the database - When the API endpoint tried to query the table, Django raised an `OperationalError` ## Solution Applied ### Step 1: Run Django Migrations ```bash python manage.py migrate ``` **Result:** ``` Applying physicians.0002_doctorratingimportjob_physicianindividualrating... OK ``` ### Step 2: Verify Migration Status ```bash python manage.py showmigrations physicians ``` **Result:** ``` physicians [X] 0001_initial [X] 0002_doctorratingimportjob_physicianindividualrating ``` Both migrations are now applied (marked with `[X]`). ### Step 3: Verify Table Exists ```bash python manage.py shell -c "from apps.physicians.models import PhysicianIndividualRating; print(f'Table exists: {PhysicianIndividualRating._meta.db_table}'); print(f'Count: {PhysicianIndividualRating.objects.count()}')" ``` **Result:** ``` Table exists: physicians_physicianindividualrating Count: 0 ``` ## Verification ✅ Table `physicians_physicianindividualrating` now exists ✅ API endpoint `/api/physicians/individual-ratings/` is accessible ✅ No more database errors when querying the physicians individual ratings ## Tables Created 1. `physicians_physicianindividualrating` - Stores individual physician ratings from HIS, CSV imports, or manual entry 2. `physicians_doctorratingimportjob` - Tracks bulk doctor rating import jobs ## Next Steps The tables are now ready to use. You can: - Import physician ratings via CSV upload - Import via HIS API integration - Manually add individual ratings - View the leaderboard and physician performance metrics ## Prevention To avoid this issue in the future: 1. Always run `python manage.py migrate` after adding new models or migrations 2. Include migration commands in deployment scripts 3. Check migration status after model changes: `python manage.py showmigrations `