prep : load demo data into your database

pm prep

Flush the database and load the default demo fixtures.

Calls initdb using the site's lino.core.site.Site.demo_fixtures.

Introduction see Play with your first Lino site.

The initdb command performs three actions in one:

  • it flushes the database specified in your settings.py, i.e. issues a DROP TABLE for every table used by your application.

  • it runs Django's migrate command to re-create all tables,

  • it runs Django's loaddata command to load the specified fixtures.

This also adds a warning filter to ignore Django's warnings about empty fixtures. (See Django ticket #18213).

This reimplements a simplified version of Django's reset command, without the possibility of deleting only some data (the thing which caused so big problems that Django 1.3. decided to deprecate this command.

Deleting all data and table definitions from a database is not always trivial. It is not tested on PostgreSQL. In MySQL we use a somewhat hackerish and MySQL-specific DROP DATABASE and CREATE DATABASE because even with constraint_checks_disabled we had sporadic errors. See 2015-03-28

We usually don't use Django's migration framework, so initdb runs Django's migrate command with the --run-syncdb option, which "allows creating tables for apps without migrations". The Django docs add that "While this isn't recommended, the migrations framework is sometimes too slow on large projects with hundreds of models." Yes, that's why we go the non-recommended way :-)

This command is defined by the lino core plugin.

This is a tested document. The following instructions are used for initialization:

>>> import lino
>>> lino.startup('lino_book.projects.min1.settings')
>>> from lino.api.doctest import *
>>> from atelier.sheller import Sheller
>>> shell = Sheller(settings.SITE.project_dir)
>>> shell("django-admin prep --help")  
usage: django-admin prep [-h] [--noinput] [--database DATABASE] [--version] [-v {0,1,2,3}] [--settings SETTINGS]
                         [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color] [--skip-checks]
                         [fixtures ...]

Flush the database and load the default demo fixtures.

positional arguments:
  fixtures              the fixtures to load

options:
  -h, --help            show this help message and exit
  --noinput             Do not prompt for input of any kind.
  --database DATABASE   Nominates a database to reset. Defaults to the "default" database.
  --version             Show program's version number and exit.
  -v {0,1,2,3}, --verbosity {0,1,2,3}
                        Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose
                        output
  --settings SETTINGS   The Python path to a settings module, e.g. "myproject.settings.main". If this isn't
                        provided, the DJANGO_SETTINGS_MODULE environment variable will be used.
  --pythonpath PYTHONPATH
                        A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".
  --traceback           Raise on CommandError exceptions.
  --no-color            Don't colorize the command output.
  --force-color         Force colorization of the command output.
  --skip-checks         Skip system checks.