使用临时数据库启动django shell [英] Start django shell with a temporary database

查看:73
本文介绍了使用临时数据库启动django shell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个临时数据库启动django shell(例如进行django测试时所做的事情)

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

是否有类似以下命令:

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

这篇关于使用临时数据库启动django shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆