Skip to content

bug: Cannot create an event on a fresh install due to missing categories #43

@iyanuashiri

Description

@iyanuashiri

A contributor (@noirtiercano ) made an excellent observation while working on another task:

"I noticed that the "Category" field in the event creation form is required, but no default categories exist in the database. This prevents event creation unless a category is manually added via admin."

This is a critical bug because it blocks the application's core user journey. On a fresh installation, no user can create an event, which makes the platform unusable. It also creates a frustrating setup experience for new contributors. This issue is to fix this blocker by seeding the database with a set of default categories.

Acceptance Criteria

  • After running python manage.py migrate on a new database, the events_category table is populated with a list of default categories.
  • A new user who signs up can immediately navigate to the "Create Event" form and see the default categories in the dropdown menu.
  • The event creation process is no longer blocked.

Implementation Guide

The best way to solve this is with a Django data migration. This is a great task for learning a core Django feature!

  1. Create an empty migration file in the events app. You can do this by running: python manage.py makemigrations events --empty --name seed_initial_categories
  2. Edit the new migration file (it will be in meethub/events/migrations/). Add a function to create the categories and use migrations. RunPython to execute it. Examples of categories include: "Technology", "Business & Networking", "Arts & Culture", "Health & Wellness", "Social & Community", "Sports & Fitness", "Hobbies & Crafts", "Education & Learning", "Food & Drink", "Outdoors & Adventure",

Here is a complete example of what the file should look like:

# meethub/events/migrations/XXXX_seed_initial_categories.py

from django.db import migrations

def create_initial_categories(apps, schema_editor):

       Category = apps.get_model('events', 'Category')
        # We can check if categories already exist to make the migration safe to re-run
        if Category.objects.exists():
        return

    initial_categories = [
        "Technology",
        "Business & Networking",
        "Arts & Culture",
        "Health & Wellness",
        "Social & Community",
        "Sports & Fitness",
        "Hobbies & Crafts",
        "Education & Learning",
        "Food & Drink",
        "Outdoors & Adventure",
    ]
    
    for category_name in initial_categories:
        Category.objects.create(
            name=category_name,
            description=f"Events related to {category_name}."
        )

class Migration(migrations.Migration):

    dependencies = [
        # Add the name of the previous migration in the 'events' app here
        ('events', '0011_alter_category_id_alter_event_details_alter_event_id'), 
    ]

    operations = [
        migrations.RunPython(create_initial_categories),
    ]```
 


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions