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?
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?
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
connection.creation.destroy_test_db()
and test.utils.tear_down_test_environment()
are also helpful. –
Surpassing db = connection.creation.create_test_db(keepdb=True)
if you want to connect to an existing database and you're using Django >= 1.8. Docs are here. –
Decentralization You could just turn autocommit off:
from django.db import transaction
transaction.set_autocommit(False)
© 2022 - 2024 — McMap. All rights reserved.