Setup Multiple Database
Modify the setting file
Add one in-memory database in setting file.
Sqlite in-memory database disappear when the calling application exit. Therefore better to initial the database in application urls.py or in the app itself
'cache': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
Add in urls.py. Add the following one after urlpattern=…
import sqlite3
import os
from django.conf import settings
base_dir = settings.BASE_DIR
schema_path = os.path.join(base_dir, 'schema.sql')
sql_statement = open(schema_path, encoding='utf-8').read()
con = sqlite3.connect(":memory:")
con.cursor().execute("PRAGMA max_page_count = 512000") # configure the page count
con.cursor().execute("PRAGMA page_size = 1024") # together with page count configure the max database size for sqlite
con.cursor().executescript(sql_statement)
dump_path = os.path.join(base_dir, 'data.json')