2.4 KiB
2.4 KiB
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
PhysicianIndividualRatingwas defined inapps/physicians/models.py - Migration files existed:
0001_initial.py0002_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
python manage.py migrate
Result:
Applying physicians.0002_doctorratingimportjob_physicianindividualrating... OK
Step 2: Verify Migration Status
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
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
physicians_physicianindividualrating- Stores individual physician ratings from HIS, CSV imports, or manual entryphysicians_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:
- Always run
python manage.py migrateafter adding new models or migrations - Include migration commands in deployment scripts
- Check migration status after model changes:
python manage.py showmigrations <app_name>