Database configuration

# Setting the database

The first step is to open the database using QSqlDatabase::addDatabase(), for instance for an in-memory SQLite database:

QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":memory:");
db.open();

You should now tell QDjango to use the database you just opened:

QDjango::setDatabase(db);

# Creating or dropping database tables

Once you have set the database and declared all your models (see Database models), you can ask QDjango to create the database tables for all models:

QDjango::createTables();

Conversely, you can ask QDjango to drop the database tables for all models:

QDjango::dropTables();

# Threading support

Internally, QDjango calls the QDjango::database() method whenever it needs a handle to the database. This method will clone the database connection as needed if it is invoked from a different thread.