Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 964
Ben Avatar asked Jun 01 '14 01:06

Ben


People also ask

How do I open Django in terminal?

00:15 For this, I head over to my terminal, in here. I'm going to start the Django shell by typing python manage.py —as so often—and then shell . This opens up a terminal. 00:30 However, it has the Django settings already imported, so it allows you to work directly from the root folder of a Django project.

How use Django command line?

Django can be installed easily using pip . In the command prompt, execute the following command: pip install django . This will download and install Django. After the installation has completed, you can verify your Django installation by executing django-admin --version in the command prompt.


1 Answers

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
like image 136
Ben Avatar answered Sep 20 '22 14:09

Ben