Hi all,
in a recent project, using Django 2.2.7, the idea was to use an additional in-memory database, as in this configuration:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'memory': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
In order to get the memory db initialized, we have this command in the config for one app called memory_db_only
:
class MemoryDbOnlyConfig(AppConfig):
name = 'memory_db_only'
def ready(self):
call_command('migrate',
app_label='memory_db_only',
verbosity=1,
interactive=False,
database='memory')
When starting a shell (python manage.py shell
) and querying some model from the memory db, it works fine:
>>> from memory_db_only.models import MyModel
>>> MyModel.objects.using("memory").all()
<QuerySet []>
However, when we add a view to the memory_db_only
app, like
def get_objects(request):
obj = MyModel.objects.using("memory").all()
return HttpResponse(str(obj))
an exception is raised:
OperationalError at /memory/objects
no such table: memory_db_only_mymodel
I would highly appreciate advice on how to setup Django in this particular scenario.
Thanks
Christoph