Search code examples
djangodjango-tests

Start django shell with a temporary database


I want to fire up the django shell with a temporary database (like what's done when doing django tests)

Is there any command like:

python manage.py testshell

where I can create a bunch of bogus models without polluting my database?


Solution

  • Nevermind, this blog post explains it

    >>> from django import test
    >>> test.utils.setup_test_environment() # Setup the environment
    >>> from django.db import connection
    >>> db = connection.creation.create_test_db() # Create the test db