用临时数据库启动django shell

Ben*_*Ben 8 django django-tests

我想用一个临时数据库启动django shell(就像做django测试时所做的那样)

有没有像这样的命令:

python manage.py testshell
Run Code Online (Sandbox Code Playgroud)

在哪里我可以创建一堆虚假模型而不污染我的数据库?

Ben*_*Ben 16

没关系,这篇博文解释了它

>>> 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
Run Code Online (Sandbox Code Playgroud)

  • @MikeDeSimone还有2天的时间,直到我可以做到,但是会做到的。 (2认同)