This error occurs because the database schema needs to be updated to include the new doctor_id column.
python fix_database_for_doctor_portal.pyThis script will:
- ✅ Add
doctor_idcolumn to users table - ✅ Create a test doctor user account
- ✅ Link the user to a doctor profile
- ✅ Display all login credentials
python migrate_add_doctor_column.py
python create_doctor_user.py# 1. Stop the application (Ctrl+C)
# 2. Delete the old database
rm instance/hospital.db # Linux/Mac
del instance\hospital.db # Windows
# 3. Recreate database with sample data
python seed_data.py
# 4. Run the fix script
python fix_database_for_doctor_portal.py
# 5. Start the application
python run.py-
Start the application:
python run.py
-
Open browser:
http://localhost:5000/auth/login -
Login as doctor:
Email: doctor@hospital.com Password: doctor123 -
You should see:
- Doctor Dashboard with statistics
- Navigation menu with doctor options
- Today's appointments and queue
-- Added to users table:
ALTER TABLE users ADD COLUMN doctor_id INTEGER;# Added doctor relationship
doctor_id = db.Column(db.Integer, db.ForeignKey("doctors.id"))
doctor = db.relationship("Doctor", backref="user_account")
# Added helper method
def is_doctor(self):
return self.role == "doctor"- Email:
admin@hospital.com - Password:
admin123 - Access: Full admin panel
- Email:
test@patient.com - Password:
test123 - Access: Patient portal
- Email:
doctor@hospital.com - Password:
doctor123 - Access: Doctor portal
Solution: Run python seed_data.py first
Solution: Run python fix_database_for_doctor_portal.py
Solution: This is fine, the script will update the existing user
Solution: Make sure you're logged in with doctor@hospital.com
Solution: Run python fix_database_for_doctor_portal.py again
migrate_add_doctor_column.py- Adds doctor_id columncreate_doctor_user.py- Creates doctor user accountfix_database_for_doctor_portal.py- Complete fix (recommended)
app/routes/doctor_portal.py- All doctor routesapp/templates/doctor/*.html- All doctor templatesapp/models/user.py- Updated with doctor supportapp/services/auth_service.py- Added @doctor_required
After running the fix script:
- Application starts without errors
- Can login as doctor
- Redirected to doctor dashboard
- Can see today's appointments
- Can view queue
- Can view appointment details
- Can update appointment status
- Navigation menu shows doctor options
If you're still having issues:
- Check the error message - It will tell you what's wrong
- Try fresh start - Delete database and recreate
- Verify seed data - Make sure doctors exist in database
- Check user role - User must have role="doctor"
- Check doctor link - User must have doctor_id set
The database schema was updated to support doctor users. Run the fix script, restart the application, and login with the doctor credentials. Everything should work perfectly!