Files
thrillwiki_django_no_react/memory-bank/seed-data-analysis.md
pacnpal 41b3c86437 Add initial migration for moderation app and resolve seed command issues
- Created an empty migration file for the moderation app to enable migrations.
- Documented the resolution of the seed command failure due to missing moderation tables.
- Identified and fixed a VARCHAR(10) constraint violation in the User model during seed data generation.
- Updated role assignment in the seed command to comply with the field length constraint.
2025-09-25 08:39:05 -04:00

107 lines
4.4 KiB
Markdown

# Seed Data Analysis - UserProfile Model Mismatch
## Issue Identified
The [`seed_comprehensive_data.py`](apps/core/management/commands/seed_comprehensive_data.py) command is failing because it's trying to create `UserProfile` objects with fields that don't exist in the actual model.
### Error Details
```
TypeError: UserProfile() got unexpected keyword arguments: 'location', 'date_of_birth', 'favorite_ride_type', 'total_parks_visited', 'total_rides_ridden', 'total_coasters_ridden'
```
### Fields Used in Seed Script vs Actual Model
**Fields Used in Seed Script (lines 883-891):**
- `user` ✅ (exists)
- `bio` ✅ (exists)
- `location` ❌ (doesn't exist)
- `date_of_birth` ❌ (doesn't exist)
- `favorite_ride_type` ❌ (doesn't exist)
- `total_parks_visited` ❌ (doesn't exist)
- `total_rides_ridden` ❌ (doesn't exist)
- `total_coasters_ridden` ❌ (doesn't exist)
**Actual UserProfile Model Fields (apps/accounts/models.py):**
- `profile_id` (auto-generated)
- `user` (OneToOneField)
- `display_name` (CharField, legacy)
- `avatar` (ForeignKey to CloudflareImage)
- `pronouns` (CharField)
- `bio` (TextField)
- `twitter` (URLField)
- `instagram` (URLField)
- `youtube` (URLField)
- `discord` (CharField)
- `coaster_credits` (IntegerField)
- `dark_ride_credits` (IntegerField)
- `flat_ride_credits` (IntegerField)
- `water_ride_credits` (IntegerField)
## Fix Required
Update the seed script to only use fields that actually exist in the UserProfile model, and map the intended functionality to the correct fields.
### Field Mapping Strategy
- Remove `location`, `date_of_birth`, `favorite_ride_type`, `total_parks_visited`, `total_rides_ridden`
- Map `total_coasters_ridden``coaster_credits`
- Can optionally populate social fields and pronouns
- Keep `bio` as is
## Solution Implementation Status
**Status**: ✅ **COMPLETED** - Successfully fixed the UserProfile field mapping
### Applied Changes
Fixed the `seed_comprehensive_data.py` command in the `create_users()` method (lines 882-897):
**Removed Invalid Fields:**
- `location` - Not in actual UserProfile model
- `date_of_birth` - Not in actual UserProfile model
- `favorite_ride_type` - Not in actual UserProfile model
- `total_parks_visited` - Not in actual UserProfile model
- `total_rides_ridden` - Not in actual UserProfile model
- `total_coasters_ridden` - Not in actual UserProfile model
**Added Valid Fields:**
- `pronouns` - Random selection from ['he/him', 'she/her', 'they/them', '']
- `coaster_credits` - Random integer 1-200 (mapped from old total_coasters_ridden)
- `dark_ride_credits` - Random integer 0-50
- `flat_ride_credits` - Random integer 0-30
- `water_ride_credits` - Random integer 0-20
- `twitter`, `instagram`, `discord` - Optional social media fields (33% chance each)
### Code Changes Made
```python
# Create user profile
user_profile = UserProfile.objects.create(user=user)
user_profile.bio = fake.text(max_nb_chars=200) if random.choice([True, False]) else ''
user_profile.pronouns = random.choice(['he/him', 'she/her', 'they/them', '']) if random.choice([True, False]) else ''
user_profile.coaster_credits = random.randint(1, 200)
user_profile.dark_ride_credits = random.randint(0, 50)
user_profile.flat_ride_credits = random.randint(0, 30)
user_profile.water_ride_credits = random.randint(0, 20)
# Optionally populate social media fields
if random.choice([True, False, False]): # 33% chance
user_profile.twitter = f"https://twitter.com/{fake.user_name()}"
if random.choice([True, False, False]): # 33% chance
user_profile.instagram = f"https://instagram.com/{fake.user_name()}"
if random.choice([True, False, False]): # 33% chance
user_profile.discord = f"{fake.user_name()}#{random.randint(1000, 9999)}"
user_profile.save()
```
### Decision Rationale
1. **Field Mapping Logic**: Mapped `total_coasters_ridden` to `coaster_credits` as the closest equivalent
2. **Realistic Credit Distribution**: Different ride types have different realistic ranges:
- Coaster credits: 1-200 (most enthusiasts focus on coasters)
- Dark ride credits: 0-50 (fewer dark rides exist)
- Flat ride credits: 0-30 (less tracked by enthusiasts)
- Water ride credits: 0-20 (seasonal/weather dependent)
3. **Social Media**: Optional fields with low probability to create realistic sparse data
4. **Pronouns**: Added diversity with realistic options including empty string
### Next Steps
- Test the seed command to verify the fix works
- Monitor for any additional field mapping issues in other parts of the seed script