Search code examples
pythondjangonosefactory-boy

factory_boy UserFactory: no such table: auth_user


I'm trying to create a UserFactory, and I get this error when running ./manage.py test:

OperationalError: no such table: auth_user

This is what my factories.py file looks like:

import factory
import django.contrib.auth.models as auth_models
from wacep.weatherroulette.models import (
    GameState, Puzzle
)


class UserFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = auth_models.User

    username = factory.Sequence(lambda n: "user_%d" % n)


class PuzzleFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Puzzle

    display_name = factory.Sequence(lambda n: 'Test Puzzle {0}'.format(n))
    description = factory.Sequence(lambda n: 'Description {0}'.format(n))


class GameStateFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = GameState

    user = UserFactory()
    current_inventory = 300

Anyone know what's happening here?


Solution

  • Oh.. Inheriting from factory.Factory instead of factory.django.DjangoModelFactory seems to fix the error.