From 5679fce87c1eb2a48f0ea2ecefb08e2285828af0 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 3 Mar 2014 18:56:11 +0800 Subject: Added first cut at reference documentation for the checks framework. --- docs/ref/checks.txt | 416 ++++++++++++++++++++++++++++------------------------ 1 file changed, 222 insertions(+), 194 deletions(-) (limited to 'docs/ref') diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt index 2e26f7feac..d560bc3999 100644 --- a/docs/ref/checks.txt +++ b/docs/ref/checks.txt @@ -4,205 +4,233 @@ System check framework .. versionadded:: 1.7 -.. module:: django.core.checks - The system check framework is a set of static checks for validating Django projects. It detects common problems and provides hints for how to fix them. The framework is extensible so you can easily add your own checks. -Checks can be triggered explicitly via the :djadmin:`check` command. Checks are -triggered implicitly before most commands, including :djadmin:`runserver` and -:djadmin:`migrate`. For performance reasons, the checks are not performed if -:setting:`DEBUG` is set to ``False``. - -Serious errors will prevent Django commands (such as :djadmin:`runserver`) from -running at all. Minor problems are reported to the console. If you have inspected -the cause of a warning and are happy to ignore it, you can hide specific warnings -using the :setting:`SILENCED_SYSTEM_CHECKS` setting in your project settings file. - -Writing your own checks -======================= - -The framework is flexible and allows you to write functions that perform -any other kind of check you may require. The following is an example stub -check function:: - - from django.core.checks import register +For details on how to add your own checks and integrate them with Django`s +system checks, see the :doc:`System check topic guide `. + +Builtin tags +------------ + +Django's system checks are organized using the following tags: + +* ``models``: Checks governing model, field and manager definitions. +* ``signals``: Checks on signal declarations and handler registrations. +* ``admin``: Checks of any admin site declarations. + +Some checks may be registered with multiple tags. + +Core system checks +------------------ + +Models +~~~~~~ + +* **models.E001**: ```` is not of the form ``app_label.app_name``. +* **models.E002**: ```` references ````, which has not been installed, or is abstract. +* **models.E003**: The model has two many-to-many relations through the intermediate model ``%s.%s``. +* **models.E004**: ``id`` can only be used as a field name if the field also sets ``primary_key=True``. +* **models.E005**: The field ```` from parent model clashes with the field ```` from parent model . +* **models.E006**: The field clashes with the field ```` from model . +* **models.E007**: Field ```` has column name ```` that is used by another field. +* **models.E008**: ``index_together`` must be a list or tuple. +* **models.E009**: All ``index_together`` elements must be lists or tuples. +* **models.E010**: ``unique_together`` must be a list or tuple. +* **models.E011**: All ``unique_together`` elements must be lists or tuples. +* **models.E012**: ``index_together/unique_together`` refers to the non-existent field ````. +* **models.E013**: ``index_together/unique_together`` refers to a ManyToManyField ````, but ManyToManyFields are not supported for that option. +* **models.E014**: ``ordering`` must be a tuple or list (even if you want to order by only one field). +* **models.E015**: ``ordering`` refers to the non-existent field ````. + +Fields +~~~~~~ + +* **fields.E001**: Field names must not end with an underscore. +* **fields.E002**: Field names must not contain "__". +* **fields.E003**: ``pk`` is a reserved word that cannot be used as a field name. +* **fields.E004**: ``choices`` must be an iterable (e.g., a list or tuple). +* **fields.E005**: ``choices`` must be an iterable returning (actual value, human readable name) tuples. +* **fields.E006**: ``db_index`` must be None, True or False. +* **fields.E007**: Primary keys must not have null=True. +* **fields.E100**: AutoFields must set primary_key=True. +* **fields.E110**: BooleanFields do not accept null values. +* **fields.E120**: CharFields must define a ``max_length`` attribute. +* **fields.E121**: ``max_length`` must be a positive integer. +* **fields.E130**: DecimalFields must define a ``decimal_places`` attribute. +* **fields.E131**: ``decimal_places`` must be a non-negative integer. +* **fields.E132**: DecimalFields must define a ``max_digits`` attribute. +* **fields.E133**: ``max_digits`` must be a non-negative integer. +* **fields.E134**: ``max_digits`` must be greater or equal to ``decimal_places``. +* **fields.E140**: FilePathFields must have either ``allow_files`` or ``allow_folders`` set to True. +* **fields.E150**: GenericIPAddressFields cannot accept blank values if null values are not allowed, as blank values are stored as nulls. + +File Fields +~~~~~~~~~~~ + +* **fields.E200**: ``unique`` is not a valid argument for a FileField. +* **fields.E201**: ``primary_key`` is not a valid argument for a FileField. +* **fields.E210**: Cannot use ImageField because Pillow is not installed. + +Related Fields +~~~~~~~~~~~~~~ + +* **fields.E300**: Field defines a relation with model ````, which is either not installed, or is abstract. +* **fields.E301**: Field defines a relation with the model ```` which has been swapped out. +* **fields.E302**: Accessor for field ```` clashes with field ````. +* **fields.E303**: Reverse query name for field ```` clashes with field ````. +* **fields.E304**: Field name ```` clashes with accessor for ````. +* **fields.E305**: Field name ```` clashes with reverse query name for ````. +* **fields.E310**: None of the fields ````, ````, ... on model ```` have a unique=True constraint. +* **fields.E311**: ```` must set unique=True because it is referenced by a ForeignKey. +* **fields.E320**: Field specifies on_delete=SET_NULL, but cannot be null. +* **fields.E321**: The field specifies on_delete=SET_DEFAULT, but has no default value. +* **fields.E330**: ManyToManyFields cannot be unique. +* **fields.E331**: Field specifies a many-to-many relation through model ``%s``, which has not been installed. +* **fields.E332**: Many-to-many fields with intermediate tables must not be symmetrical. +* **fields.E333**: The model is used as an intermediate model by ````, but it has more than two foreign keys to ````, which is ambiguous. +* **fields.E334**: The model is used as an intermediate model by ````, but it has more than one foreign key from ````, which is ambiguous. +* **fields.E335**: The model is used as an intermediate model by ````, but it has more than one foreign key to ````, which is ambiguous. +* **fields.E336**: The model is used as an intermediary model by ````, but it does not have foreign key to ```` or ````." + +Signals +~~~~~~~ + +* **signals.E001**: was connected to the ```` signal with a lazy reference to the ```` sender, which has not been installed. + +Admin +----- + +Admin checks are all performed as part of the ``admin`` tag. + +The following checks are performend on any +:class:`~django.contrib.admin.ModelAdmin` (or subclass) that is registered +with the admin site: + +* **admin.E001**: The value of ``raw_id_fields`` must be a list or tuple. +* **admin.E002**: The value of ``raw_id_fields[n]`` refers to ````, which is not an attribute of ````. +* **admin.E003**: The value of ``raw_id_fields[n]`` must be a ForeignKey or ManyToManyField. +* **admin.E004**: The value of ``fields`` must be a list or tuple. +* **admin.E005**: Both ``fieldsets`` and ``fields`` are specified. +* **admin.E006**: The value of ``fields`` contains duplicate field(s). +* **admin.E007**: The value of ``fieldsets`` must be a list or tuple. +* **admin.E008**: The value of ``fieldsets[n]`` must be a list or tuple. +* **admin.E009**: The value of ``fieldsets[n]`` must be of length 2. +* **admin.E010**: The value of ``fieldsets[n][1]`` must be a dictionary. +* **admin.E011**: The value of ``fieldsets[n][1]`` must contain the key ``fields``. +* **admin.E012**: There are duplicate field(s) in ``fieldsets[n][1]`` +* **admin.E013**: ``fields[n]/fieldsets[n][m]`` cannot include the ManyToManyField ````, because that field manually specifies a relationship model. +* **admin.E014**: The value of ``exclude`` must be a list or tuple. +* **admin.E015**: The value of ``exclude`` contains duplicate field(s). +* **admin.E016**: The value of ``form`` must inherit from ``BaseModelForm``. +* **admin.E017**: The value of ``filter_vertical`` must be a list or tuple. +* **admin.E018**: The value of ``filter_horizontal`` must be a list or tuple. +* **admin.E019**: The value of ``filter_vertical[n]/filter_vertical[n]`` refers to ````, which is not an attribute of ````. +* **admin.E020**: The value of ``filter_vertical[n]/filter_vertical[n]`` must be a ManyToManyField. +* **admin.E021**: The value of ``radio_fields`` must be a dictionary. +* **admin.E022**: The value of ``radio_fields`` refers to ````, which is not an attribute of ````. +* **admin.E023**: The value of ``radio_fields`` refers to ````, which is not a ForeignKey, and does not have a ``choices`` definition. +* **admin.E024**: The value of ``radio_fields[]`` must be either admin.HORIZONTAL nor admin.VERTICAL. +* **admin.E025**: The value of ``view_on_site`` must be either a callable or a boolean value. +* **admin.E026**: The value of ``prepopulated_fields`` must be a dictionary. +* **admin.E027**: The value of ``prepopulated_fields`` refers to ````, which is not an attribute of ````. +* **admin.E028**: The value of ``prepopulated_fields`` refers to ````, which must not be a DateTimeField, ForeignKey or ManyToManyField. +* **admin.E029**: The value of ``prepopulated_fields[]`` must be a list or tuple. +* **admin.E030**: The value of ``prepopulated_fields`` refers to ````, which is not an attribute of ````. +* **admin.E031**: The value of ``ordering`` must be a list or tuple. +* **admin.E032**: The value of ``ordering`` has the random ordering marker ``?``, but contains other fields as well. +* **admin.E033**: The value of ``ordering`` refers to ````, which is not an attribute of ````. +* **admin.E034**: The value of ``readonly_fields`` must be a list or tuple. +* **admin.E035**: The value of ``readonly_fields[n]`` is not a callable, an attribute of ````, or an attribute of ````. + +ModelAdmin +~~~~~~~~~~ + +The following checks are performed on any +:class:`~django.contrib.admin.ModelAdmin` that is registered +with the admin site: + +* **admin.E101**: The value of ``save_as`` must be a boolean. +* **admin.E102**: The value of ``save_on_top`` must be a boolean. +* **admin.E103**: The value of ``inlines`` must be a list or tuple. +* **admin.E104**: ```` must inherit from ``BaseModelAdmin``. +* **admin.E105**: ```` must have a ``model`` attribute. +* **admin.E106**: The value of ``.model`` must be a Model. +* **admin.E107**: The value of ``list_display`` must be a list or tuple. +* **admin.E108**: The value of ``list_display[n]`` refers to ``