# Foreign Key Constraint Resolution - 2025-02-09 (Updated)

## Revision Note
Corrected migration sequence conflict:
- Original 0002 migration conflicted with existing 0002 file
- Created new migration as 0012_cleanup_invalid_designers.py
- Deleted conflicting 0002_cleanup_invalid_designers.py

## Updated Resolution Steps
1. Created conflict-free migration 0012
2. Verified migration dependencies:
   ```python
   dependencies = [
       ('rides', '0011_merge_20250209_1143'),
       ('designers', '0001_initial'),
   ]
   ```
3. New migration command:
   ```bash
   python manage.py migrate rides 0012_cleanup_invalid_designers
   ```

## PGHistory Migration Fix - 2025-02-09
Foreign key constraint violation during pghistory migration:
1. Issue: `rides_ride_designer_id_172b997d_fk_designers_designer_id` constraint violation during 0010_rideevent migration
2. Resolution:
   - Created new cleanup migration (0009_cleanup_invalid_designers_pre_events.py) to run before event table creation
   - Updated migration dependencies to ensure proper sequencing:
     ```python
     # 0009_cleanup_invalid_designers_pre_events.py
     dependencies = [
         ('rides', '0008_historicalride_post_closing_status_and_more'),
         ('designers', '0001_initial'),
     ]
     ```
   - Created merge migration (0013_merge_20250209_1214.py) to resolve multiple leaf nodes
3. Final Migration Sequence:
   - Base migrations up to 0008
   - Cleanup migration (0009_cleanup_invalid_designers_pre_events)
   - Event table creation (0010_rideevent_ridemodelevent_and_more)
   - Merge migrations (0011, 0012, 0013)