checks.txt 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. ======================
  2. System check framework
  3. ======================
  4. .. currentmodule:: django.core.checks
  5. The system check framework is a set of static checks for validating Django
  6. projects. It detects common problems and provides hints for how to fix them.
  7. The framework is extensible so you can easily add your own checks.
  8. For details on how to add your own checks and integrate them with Django's
  9. system checks, see the :doc:`System check topic guide </topics/checks>`.
  10. API Reference
  11. =============
  12. ``CheckMessage``
  13. -----------------
  14. .. class:: CheckMessage(level, msg, hint=None, obj=None, id=None)
  15. The warnings and errors raised by system checks must be instances of
  16. ``CheckMessage``. An instance encapsulates a single reportable error or
  17. warning. It also provides context and hints applicable to the message, and a
  18. unique identifier that is used for filtering purposes.
  19. Constructor arguments are:
  20. ``level``
  21. The severity of the message. Use one of the predefined values: ``DEBUG``,
  22. ``INFO``, ``WARNING``, ``ERROR``, ``CRITICAL``. If the level is greater or
  23. equal to ``ERROR``, then Django will prevent management commands from
  24. executing. Messages with level lower than ``ERROR`` (i.e. warnings) are
  25. reported to the console, but can be silenced.
  26. ``msg``
  27. A short (less than 80 characters) string describing the problem. The string
  28. should *not* contain newlines.
  29. ``hint``
  30. A single-line string providing a hint for fixing the problem. If no hint
  31. can be provided, or the hint is self-evident from the error message, the
  32. hint can be omitted, or a value of ``None`` can be used.
  33. ``obj``
  34. Optional. An object providing context for the message (for example, the
  35. model where the problem was discovered). The object should be a model,
  36. field, or manager or any other object that defines ``__str__`` method (on
  37. Python 2 you need to define ``__unicode__`` method). The method is used
  38. while reporting all messages and its result precedes the message.
  39. ``id``
  40. Optional string. A unique identifier for the issue. Identifiers should
  41. follow the pattern ``applabel.X001``, where ``X`` is one of the letters
  42. ``CEWID``, indicating the message severity (``C`` for criticals, ``E`` for
  43. errors and so). The number can be allocated by the application, but should
  44. be unique within that application.
  45. There are subclasses to make creating messages with common levels easier. When
  46. using them you can omit the ``level`` argument because it is implied by the
  47. class name.
  48. .. class:: Debug(msg, hint=None, obj=None, id=None)
  49. .. class:: Info(msg, hint=None, obj=None, id=None)
  50. .. class:: Warning(msg, hint=None obj=None, id=None)
  51. .. class:: Error(msg, hint=None, obj=None, id=None)
  52. .. class:: Critical(msg, hint=None, obj=None, id=None)
  53. Builtin checks
  54. ==============
  55. .. _system-check-builtin-tags:
  56. Builtin tags
  57. ------------
  58. Django's system checks are organized using the following tags:
  59. * ``models``: Checks governing model, field and manager definitions.
  60. * ``signals``: Checks on signal declarations and handler registrations.
  61. * ``admin``: Checks of any admin site declarations.
  62. * ``compatibility``: Flagging potential problems with version upgrades.
  63. * ``security``: Checks security related configuration.
  64. * ``templates``: Checks template related configuration.
  65. * ``caches``: Checks cache related configuration.
  66. * ``urls``: Checks URL configuration.
  67. * ``database``: Checks database-related configuration issues. Database checks
  68. are not run by default because they do more than static code analysis as
  69. regular checks do. They are only run by the :djadmin:`migrate` command or if
  70. you specify the ``database`` tag when calling the :djadmin:`check` command.
  71. .. versionadded:: 1.10
  72. The ``database`` tag was added.
  73. Some checks may be registered with multiple tags.
  74. Core system checks
  75. ------------------
  76. Models
  77. ~~~~~~
  78. * **models.E001**: ``<swappable>`` is not of the form ``app_label.app_name``.
  79. * **models.E002**: ``<SETTING>`` references ``<model>``, which has not been
  80. installed, or is abstract.
  81. * **models.E003**: The model has two many-to-many relations through the
  82. intermediate model ``<app_label>.<model>``.
  83. * **models.E004**: ``id`` can only be used as a field name if the field also
  84. sets ``primary_key=True``.
  85. * **models.E005**: The field ``<field name>`` from parent model ``<model>``
  86. clashes with the field ``<field name>`` from parent model ``<model>``.
  87. * **models.E006**: The field clashes with the field ``<field name>`` from model
  88. ``<model>``.
  89. * **models.E007**: Field ``<field name>`` has column name ``<column name>``
  90. that is used by another field.
  91. * **models.E008**: ``index_together`` must be a list or tuple.
  92. * **models.E009**: All ``index_together`` elements must be lists or tuples.
  93. * **models.E010**: ``unique_together`` must be a list or tuple.
  94. * **models.E011**: All ``unique_together`` elements must be lists or tuples.
  95. * **models.E012**: ``index_together/unique_together`` refers to the
  96. non-existent field ``<field name>``.
  97. * **models.E013**: ``index_together/unique_together`` refers to a
  98. ``ManyToManyField`` ``<field name>``, but ``ManyToManyField``\s are not
  99. supported for that option.
  100. * **models.E014**: ``ordering`` must be a tuple or list (even if you want to
  101. order by only one field).
  102. * **models.E015**: ``ordering`` refers to the non-existent field
  103. ``<field name>``.
  104. * **models.E016**: ``index_together/unique_together`` refers to field
  105. ``<field_name>`` which is not local to model ``<model>``.
  106. * **models.E017**: Proxy model ``<model>`` contains model fields.
  107. * **models.E018**: Autogenerated column name too long for field ``<field>``.
  108. Maximum length is ``<maximum length>`` for database ``<alias>``.
  109. * **models.E019**: Autogenerated column name too long for M2M field
  110. ``<M2M field>``. Maximum length is ``<maximum length>`` for database
  111. ``<alias>``.
  112. * **models.E020**: The ``<model>.check()`` class method is currently overridden.
  113. * **models.E021**: ``ordering`` and ``order_with_respect_to`` cannot be used
  114. together.
  115. Fields
  116. ~~~~~~
  117. * **fields.E001**: Field names must not end with an underscore.
  118. * **fields.E002**: Field names must not contain ``"__"``.
  119. * **fields.E003**: ``pk`` is a reserved word that cannot be used as a field
  120. name.
  121. * **fields.E004**: ``choices`` must be an iterable (e.g., a list or tuple).
  122. * **fields.E005**: ``choices`` must be an iterable returning ``(actual value,
  123. human readable name)`` tuples.
  124. * **fields.E006**: ``db_index`` must be ``None``, ``True`` or ``False``.
  125. * **fields.E007**: Primary keys must not have ``null=True``.
  126. * **fields.E100**: ``AutoField``\s must set primary_key=True.
  127. * **fields.E110**: ``BooleanField``\s do not accept null values.
  128. * **fields.E120**: ``CharField``\s must define a ``max_length`` attribute.
  129. * **fields.E121**: ``max_length`` must be a positive integer.
  130. * **fields.W122**: ``max_length`` is ignored when used with ``IntegerField``.
  131. * **fields.E130**: ``DecimalField``\s must define a ``decimal_places`` attribute.
  132. * **fields.E131**: ``decimal_places`` must be a non-negative integer.
  133. * **fields.E132**: ``DecimalField``\s must define a ``max_digits`` attribute.
  134. * **fields.E133**: ``max_digits`` must be a non-negative integer.
  135. * **fields.E134**: ``max_digits`` must be greater or equal to ``decimal_places``.
  136. * **fields.E140**: ``FilePathField``\s must have either ``allow_files`` or
  137. ``allow_folders`` set to True.
  138. * **fields.E150**: ``GenericIPAddressField``\s cannot accept blank values if
  139. null values are not allowed, as blank values are stored as nulls.
  140. * **fields.E160**: The options ``auto_now``, ``auto_now_add``, and ``default``
  141. are mutually exclusive. Only one of these options may be present.
  142. * **fields.W161**: Fixed default value provided.
  143. * **fields.E900**: ``IPAddressField`` has been removed except for support in
  144. historical migrations.
  145. * **fields.W900**: ``IPAddressField`` has been deprecated. Support for it
  146. (except in historical migrations) will be removed in Django 1.9. *This check
  147. appeared in Django 1.7 and 1.8*.
  148. * **fields.W901**: ``CommaSeparatedIntegerField`` has been deprecated. Support
  149. for it (except in historical migrations) will be removed in Django 2.0.
  150. File Fields
  151. ~~~~~~~~~~~
  152. * **fields.E200**: ``unique`` is not a valid argument for a ``FileField``.
  153. * **fields.E201**: ``primary_key`` is not a valid argument for a ``FileField``.
  154. * **fields.E210**: Cannot use ``ImageField`` because Pillow is not installed.
  155. Related Fields
  156. ~~~~~~~~~~~~~~
  157. * **fields.E300**: Field defines a relation with model ``<model>``, which is
  158. either not installed, or is abstract.
  159. * **fields.E301**: Field defines a relation with the model ``<model>`` which
  160. has been swapped out.
  161. * **fields.E302**: Accessor for field ``<field name>`` clashes with field
  162. ``<field name>``.
  163. * **fields.E303**: Reverse query name for field ``<field name>`` clashes with
  164. field ``<field name>``.
  165. * **fields.E304**: Field name ``<field name>`` clashes with accessor for
  166. ``<field name>``.
  167. * **fields.E305**: Field name ``<field name>`` clashes with reverse query name
  168. for ``<field name>``.
  169. * **fields.E306**: Related name must be a valid Python identifier or end with
  170. a ``'+'``.
  171. * **fields.E310**: No subset of the fields ``<field1>``, ``<field2>``, ... on
  172. model ``<model>`` is unique. Add ``unique=True`` on any of those fields or
  173. add at least a subset of them to a unique_together constraint.
  174. * **fields.E311**: ``<model>`` must set ``unique=True`` because it is
  175. referenced by a ``ForeignKey``.
  176. * **fields.E320**: Field specifies ``on_delete=SET_NULL``, but cannot be null.
  177. * **fields.E321**: The field specifies ``on_delete=SET_DEFAULT``, but has no
  178. default value.
  179. * **fields.E330**: ``ManyToManyField``\s cannot be unique.
  180. * **fields.E331**: Field specifies a many-to-many relation through model
  181. ``<model>``, which has not been installed.
  182. * **fields.E332**: Many-to-many fields with intermediate tables must not be
  183. symmetrical.
  184. * **fields.E333**: The model is used as an intermediate model by ``<model>``,
  185. but it has more than two foreign keys to ``<model>``, which is ambiguous.
  186. You must specify which two foreign keys Django should use via the
  187. ``through_fields`` keyword argument.
  188. * **fields.E334**: The model is used as an intermediate model by ``<model>``,
  189. but it has more than one foreign key from ``<model>``, which is ambiguous.
  190. You must specify which foreign key Django should use via the
  191. ``through_fields`` keyword argument.
  192. * **fields.E335**: The model is used as an intermediate model by ``<model>``,
  193. but it has more than one foreign key to ``<model>``, which is ambiguous.
  194. You must specify which foreign key Django should use via the
  195. ``through_fields`` keyword argument.
  196. * **fields.E336**: The model is used as an intermediary model by ``<model>``,
  197. but it does not have foreign key to ``<model>`` or ``<model>``.
  198. * **fields.E337**: Field specifies ``through_fields`` but does not provide the
  199. names of the two link fields that should be used for the relation through
  200. ``<model>``.
  201. * **fields.E338**: The intermediary model ``<through model>`` has no field
  202. ``<field name>``.
  203. * **fields.E339**: ``<model>.<field name>`` is not a foreign key to ``<model>``.
  204. * **fields.W340**: ``null`` has no effect on ``ManyToManyField``.
  205. * **fields.W341**: ``ManyToManyField`` does not support ``validators``.
  206. * **fields.W342**: Setting ``unique=True`` on a ``ForeignKey`` has the same
  207. effect as using a ``OneToOneField``.
  208. Signals
  209. ~~~~~~~
  210. * **signals.E001**: ``<handler>`` was connected to the ``<signal>`` signal with
  211. a lazy reference to the ``<model>`` sender, which has not been installed.
  212. Backwards Compatibility
  213. ~~~~~~~~~~~~~~~~~~~~~~~
  214. The following checks are performed to warn the user of any potential problems
  215. that might occur as a result of a version upgrade.
  216. * **1_6.W001**: Some project unit tests may not execute as expected. *This
  217. check was removed in Django 1.8 due to false positives*.
  218. * **1_6.W002**: ``BooleanField`` does not have a default value. *This
  219. check was removed in Django 1.8 due to false positives*.
  220. * **1_7.W001**: Django 1.7 changed the global defaults for the
  221. ``MIDDLEWARE_CLASSES.``
  222. ``django.contrib.sessions.middleware.SessionMiddleware``,
  223. ``django.contrib.auth.middleware.AuthenticationMiddleware``, and
  224. ``django.contrib.messages.middleware.MessageMiddleware`` were removed from
  225. the defaults. If your project needs these middleware then you should
  226. configure this setting. *This check was removed in Django 1.9*.
  227. * **1_8.W001**: The standalone ``TEMPLATE_*`` settings were deprecated in
  228. Django 1.8 and the :setting:`TEMPLATES` dictionary takes precedence. You must
  229. put the values of the following settings into your defaults ``TEMPLATES``
  230. dict: ``TEMPLATE_DIRS``, ``TEMPLATE_CONTEXT_PROCESSORS``, ``TEMPLATE_DEBUG``,
  231. ``TEMPLATE_LOADERS``, ``TEMPLATE_STRING_IF_INVALID``.
  232. Admin
  233. -----
  234. Admin checks are all performed as part of the ``admin`` tag.
  235. The following checks are performed on any
  236. :class:`~django.contrib.admin.ModelAdmin` (or subclass) that is registered
  237. with the admin site:
  238. * **admin.E001**: The value of ``raw_id_fields`` must be a list or tuple.
  239. * **admin.E002**: The value of ``raw_id_fields[n]`` refers to ``<field name>``,
  240. which is not an attribute of ``<model>``.
  241. * **admin.E003**: The value of ``raw_id_fields[n]`` must be a foreign key or
  242. a many-to-many field.
  243. * **admin.E004**: The value of ``fields`` must be a list or tuple.
  244. * **admin.E005**: Both ``fieldsets`` and ``fields`` are specified.
  245. * **admin.E006**: The value of ``fields`` contains duplicate field(s).
  246. * **admin.E007**: The value of ``fieldsets`` must be a list or tuple.
  247. * **admin.E008**: The value of ``fieldsets[n]`` must be a list or tuple.
  248. * **admin.E009**: The value of ``fieldsets[n]`` must be of length 2.
  249. * **admin.E010**: The value of ``fieldsets[n][1]`` must be a dictionary.
  250. * **admin.E011**: The value of ``fieldsets[n][1]`` must contain the key
  251. ``fields``.
  252. * **admin.E012**: There are duplicate field(s) in ``fieldsets[n][1]``.
  253. * **admin.E013**: ``fields[n]/fieldsets[n][m]`` cannot include the
  254. many-to-many field ``<field name>``, because that field manually specifies a
  255. relationship model.
  256. * **admin.E014**: The value of ``exclude`` must be a list or tuple.
  257. * **admin.E015**: The value of ``exclude`` contains duplicate field(s).
  258. * **admin.E016**: The value of ``form`` must inherit from ``BaseModelForm``.
  259. * **admin.E017**: The value of ``filter_vertical`` must be a list or tuple.
  260. * **admin.E018**: The value of ``filter_horizontal`` must be a list or tuple.
  261. * **admin.E019**: The value of ``filter_vertical[n]/filter_vertical[n]`` refers
  262. to ``<field name>``, which is not an attribute of ``<model>``.
  263. * **admin.E020**: The value of ``filter_vertical[n]/filter_vertical[n]`` must
  264. be a many-to-many field.
  265. * **admin.E021**: The value of ``radio_fields`` must be a dictionary.
  266. * **admin.E022**: The value of ``radio_fields`` refers to ``<field name>``,
  267. which is not an attribute of ``<model>``.
  268. * **admin.E023**: The value of ``radio_fields`` refers to ``<field name>``,
  269. which is not a ``ForeignKey``, and does not have a ``choices`` definition.
  270. * **admin.E024**: The value of ``radio_fields[<field name>]`` must be either
  271. ``admin.HORIZONTAL`` or ``admin.VERTICAL``.
  272. * **admin.E025**: The value of ``view_on_site`` must be either a callable or a
  273. boolean value.
  274. * **admin.E026**: The value of ``prepopulated_fields`` must be a dictionary.
  275. * **admin.E027**: The value of ``prepopulated_fields`` refers to
  276. ``<field name>``, which is not an attribute of ``<model>``.
  277. * **admin.E028**: The value of ``prepopulated_fields`` refers to
  278. ``<field name>``, which must not be a ``DateTimeField``, a foreign key or a
  279. many-to-many field.
  280. * **admin.E029**: The value of ``prepopulated_fields[<field name>]`` must be a
  281. list or tuple.
  282. * **admin.E030**: The value of ``prepopulated_fields`` refers to
  283. ``<field name>``, which is not an attribute of ``<model>``.
  284. * **admin.E031**: The value of ``ordering`` must be a list or tuple.
  285. * **admin.E032**: The value of ``ordering`` has the random ordering marker
  286. ``?``, but contains other fields as well.
  287. * **admin.E033**: The value of ``ordering`` refers to ``<field name>``, which
  288. is not an attribute of ``<model>``.
  289. * **admin.E034**: The value of ``readonly_fields`` must be a list or tuple.
  290. * **admin.E035**: The value of ``readonly_fields[n]`` is not a callable, an
  291. attribute of ``<ModelAdmin class>``, or an attribute of ``<model>``.
  292. ``ModelAdmin``
  293. ~~~~~~~~~~~~~~
  294. The following checks are performed on any
  295. :class:`~django.contrib.admin.ModelAdmin` that is registered
  296. with the admin site:
  297. * **admin.E101**: The value of ``save_as`` must be a boolean.
  298. * **admin.E102**: The value of ``save_on_top`` must be a boolean.
  299. * **admin.E103**: The value of ``inlines`` must be a list or tuple.
  300. * **admin.E104**: ``<InlineModelAdmin class>`` must inherit from
  301. ``BaseModelAdmin``.
  302. * **admin.E105**: ``<InlineModelAdmin class>`` must have a ``model`` attribute.
  303. * **admin.E106**: The value of ``<InlineModelAdmin class>.model`` must be a
  304. ``Model``.
  305. * **admin.E107**: The value of ``list_display`` must be a list or tuple.
  306. * **admin.E108**: The value of ``list_display[n]`` refers to ``<label>``,
  307. which is not a callable, an attribute of ``<ModelAdmin class>``, or an
  308. attribute or method on ``<model>``.
  309. * **admin.E109**: The value of ``list_display[n]`` must not be a
  310. many-to-many field.
  311. * **admin.E110**: The value of ``list_display_links`` must be a list, a tuple,
  312. or ``None``.
  313. * **admin.E111**: The value of ``list_display_links[n]`` refers to ``<label>``,
  314. which is not defined in ``list_display``.
  315. * **admin.E112**: The value of ``list_filter`` must be a list or tuple.
  316. * **admin.E113**: The value of ``list_filter[n]`` must inherit from
  317. ``ListFilter``.
  318. * **admin.E114**: The value of ``list_filter[n]`` must not inherit from
  319. ``FieldListFilter``.
  320. * **admin.E115**: The value of ``list_filter[n][1]`` must inherit from
  321. ``FieldListFilter``.
  322. * **admin.E116**: The value of ``list_filter[n]`` refers to ``<label>``,
  323. which does not refer to a Field.
  324. * **admin.E117**: The value of ``list_select_related`` must be a boolean,
  325. tuple or list.
  326. * **admin.E118**: The value of ``list_per_page`` must be an integer.
  327. * **admin.E119**: The value of ``list_max_show_all`` must be an integer.
  328. * **admin.E120**: The value of ``list_editable`` must be a list or tuple.
  329. * **admin.E121**: The value of ``list_editable[n]`` refers to ``<label>``,
  330. which is not an attribute of ``<model>``.
  331. * **admin.E122**: The value of ``list_editable[n]`` refers to ``<label>``,
  332. which is not contained in ``list_display``.
  333. * **admin.E123**: The value of ``list_editable[n]`` cannot be in both
  334. ``list_editable`` and ``list_display_links``.
  335. * **admin.E124**: The value of ``list_editable[n]`` refers to the first field
  336. in ``list_display`` (``<label>``), which cannot be used unless
  337. ``list_display_links`` is set.
  338. * **admin.E125**: The value of ``list_editable[n]`` refers to ``<field name>``,
  339. which is not editable through the admin.
  340. * **admin.E126**: The value of ``search_fields`` must be a list or tuple.
  341. * **admin.E127**: The value of ``date_hierarchy`` refers to ``<field name>``,
  342. which is not an attribute of ``<model>``.
  343. * **admin.E128**: The value of ``date_hierarchy`` must be a ``DateField`` or
  344. ``DateTimeField``.
  345. ``InlineModelAdmin``
  346. ~~~~~~~~~~~~~~~~~~~~
  347. The following checks are performed on any
  348. :class:`~django.contrib.admin.InlineModelAdmin` that is registered as an
  349. inline on a :class:`~django.contrib.admin.ModelAdmin`.
  350. * **admin.E201**: Cannot exclude the field ``<field name>``, because it is the
  351. foreign key to the parent model ``<app_label>.<model>``.
  352. * **admin.E202**: ``<model>`` has no ``ForeignKey`` to ``<parent model>``./
  353. ``<model>`` has more than one ``ForeignKey`` to ``<parent model>``.
  354. * **admin.E203**: The value of ``extra`` must be an integer.
  355. * **admin.E204**: The value of ``max_num`` must be an integer.
  356. * **admin.E205**: The value of ``min_num`` must be an integer.
  357. * **admin.E206**: The value of ``formset`` must inherit from
  358. ``BaseModelFormSet``.
  359. ``GenericInlineModelAdmin``
  360. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  361. The following checks are performed on any
  362. :class:`~django.contrib.contenttypes.admin.GenericInlineModelAdmin` that is
  363. registered as an inline on a :class:`~django.contrib.admin.ModelAdmin`.
  364. * **admin.E301**: ``'ct_field'`` references ``<label>``, which is not a field
  365. on ``<model>``.
  366. * **admin.E302**: ``'ct_fk_field'`` references ``<label>``, which is not a
  367. field on ``<model>``.
  368. * **admin.E303**: ``<model>`` has no ``GenericForeignKey``.
  369. * **admin.E304**: ``<model>`` has no ``GenericForeignKey`` using content type
  370. field ``<field name>`` and object ID field ``<field name>``.
  371. ``AdminSite``
  372. ~~~~~~~~~~~~~
  373. The following checks are performed on the default
  374. :class:`~django.contrib.admin.AdminSite`:
  375. * **admin.E401**: :mod:`django.contrib.contenttypes` must be in
  376. :setting:`INSTALLED_APPS` in order to use the admin application.
  377. * **admin.E402**: :mod:`django.contrib.auth.context_processors.auth`
  378. must be in :setting:`TEMPLATES` in order to use the admin application.
  379. Auth
  380. ----
  381. * **auth.E001**: ``REQUIRED_FIELDS`` must be a list or tuple.
  382. * **auth.E002**: The field named as the ``USERNAME_FIELD`` for a custom user
  383. model must not be included in ``REQUIRED_FIELDS``.
  384. * **auth.E003**: ``<field>`` must be unique because it is named as the
  385. ``USERNAME_FIELD``.
  386. * **auth.W004**: ``<field>`` is named as the ``USERNAME_FIELD``, but it is not
  387. unique.
  388. * **auth.E005**: The permission codenamed ``<codename>`` clashes with a builtin
  389. permission for model ``<model>``.
  390. * **auth.E006**: The permission codenamed ``<codename>`` is duplicated for model
  391. ``<model>``.
  392. * **auth.E007**: The :attr:`verbose_name
  393. <django.db.models.Options.verbose_name>` of model ``<model>`` must be at most
  394. 244 characters for its builtin permission names
  395. to be at most 255 characters.
  396. * **auth.E008**: The permission named ``<name>`` of model ``<model>`` is longer
  397. than 255 characters.
  398. * **auth.C009**: ``<User model>.is_anonymous`` must be an attribute or property
  399. rather than a method. Ignoring this is a security issue as anonymous users
  400. will be treated as authenticated!
  401. * **auth.C010**: ``<User model>.is_authenticated`` must be an attribute or
  402. property rather than a method. Ignoring this is a security issue as anonymous
  403. users will be treated as authenticated!
  404. Content Types
  405. -------------
  406. The following checks are performed when a model contains a
  407. :class:`~django.contrib.contenttypes.fields.GenericForeignKey` or
  408. :class:`~django.contrib.contenttypes.fields.GenericRelation`:
  409. * **contenttypes.E001**: The ``GenericForeignKey`` object ID references the
  410. non-existent field ``<field>``.
  411. * **contenttypes.E002**: The ``GenericForeignKey`` content type references the
  412. non-existent field ``<field>``.
  413. * **contenttypes.E003**: ``<field>`` is not a ``ForeignKey``.
  414. * **contenttypes.E004**: ``<field>`` is not a ``ForeignKey`` to
  415. ``contenttypes.ContentType``.
  416. Security
  417. --------
  418. The security checks do not make your site secure. They do not audit code, do
  419. intrusion detection, or do anything particularly complex. Rather, they help
  420. perform an automated, low-hanging-fruit checklist. They help you remember the
  421. simple things that improve your site's security.
  422. Some of these checks may not be appropriate for your particular deployment
  423. configuration. For instance, if you do your HTTP to HTTPS redirection in a load
  424. balancer, it'd be irritating to be constantly warned about not having enabled
  425. :setting:`SECURE_SSL_REDIRECT`. Use :setting:`SILENCED_SYSTEM_CHECKS` to
  426. silence unneeded checks.
  427. The following checks are run if you use the :option:`check --deploy` option:
  428. * **security.W001**: You do not have
  429. :class:`django.middleware.security.SecurityMiddleware` in your
  430. :setting:`MIDDLEWARE`/:setting:`MIDDLEWARE_CLASSES` so the :setting:`SECURE_HSTS_SECONDS`,
  431. :setting:`SECURE_CONTENT_TYPE_NOSNIFF`, :setting:`SECURE_BROWSER_XSS_FILTER`,
  432. and :setting:`SECURE_SSL_REDIRECT` settings will have no effect.
  433. * **security.W002**: You do not have
  434. :class:`django.middleware.clickjacking.XFrameOptionsMiddleware` in your
  435. :setting:`MIDDLEWARE`/:setting:`MIDDLEWARE_CLASSES`, so your pages will not be served with an
  436. ``'x-frame-options'`` header. Unless there is a good reason for your
  437. site to be served in a frame, you should consider enabling this
  438. header to help prevent clickjacking attacks.
  439. * **security.W003**: You don't appear to be using Django's built-in cross-site
  440. request forgery protection via the middleware
  441. (:class:`django.middleware.csrf.CsrfViewMiddleware` is not in your
  442. :setting:`MIDDLEWARE`/:setting:`MIDDLEWARE_CLASSES`). Enabling the middleware is the safest
  443. approach to ensure you don't leave any holes.
  444. * **security.W004**: You have not set a value for the
  445. :setting:`SECURE_HSTS_SECONDS` setting. If your entire site is served only
  446. over SSL, you may want to consider setting a value and enabling :ref:`HTTP
  447. Strict Transport Security <http-strict-transport-security>`. Be sure to read
  448. the documentation first; enabling HSTS carelessly can cause serious,
  449. irreversible problems.
  450. * **security.W005**: You have not set the
  451. :setting:`SECURE_HSTS_INCLUDE_SUBDOMAINS` setting to ``True``. Without this,
  452. your site is potentially vulnerable to attack via an insecure connection to a
  453. subdomain. Only set this to ``True`` if you are certain that all subdomains of
  454. your domain should be served exclusively via SSL.
  455. * **security.W006**: Your :setting:`SECURE_CONTENT_TYPE_NOSNIFF` setting is not
  456. set to ``True``, so your pages will not be served with an
  457. ``'x-content-type-options: nosniff'`` header. You should consider enabling
  458. this header to prevent the browser from identifying content types incorrectly.
  459. * **security.W007**: Your :setting:`SECURE_BROWSER_XSS_FILTER` setting is not
  460. set to ``True``, so your pages will not be served with an
  461. ``'x-xss-protection: 1; mode=block'`` header. You should consider enabling
  462. this header to activate the browser's XSS filtering and help prevent XSS
  463. attacks.
  464. * **security.W008**: Your :setting:`SECURE_SSL_REDIRECT` setting is not set to
  465. ``True``. Unless your site should be available over both SSL and non-SSL
  466. connections, you may want to either set this setting to ``True`` or configure
  467. a load balancer or reverse-proxy server to redirect all connections to HTTPS.
  468. * **security.W009**: Your :setting:`SECRET_KEY` has less than 50 characters or
  469. less than 5 unique characters. Please generate a long and random
  470. ``SECRET_KEY``, otherwise many of Django's security-critical features will be
  471. vulnerable to attack.
  472. * **security.W010**: You have :mod:`django.contrib.sessions` in your
  473. :setting:`INSTALLED_APPS` but you have not set
  474. :setting:`SESSION_COOKIE_SECURE` to ``True``. Using a secure-only session
  475. cookie makes it more difficult for network traffic sniffers to hijack user
  476. sessions.
  477. * **security.W011**: You have
  478. :class:`django.contrib.sessions.middleware.SessionMiddleware` in your
  479. :setting:`MIDDLEWARE`/:setting:`MIDDLEWARE_CLASSES`, but you have not set
  480. :setting:`SESSION_COOKIE_SECURE` to ``True``. Using a secure-only session
  481. cookie makes it more difficult for network traffic sniffers to hijack user
  482. sessions.
  483. * **security.W012**: :setting:`SESSION_COOKIE_SECURE` is not set to ``True``.
  484. Using a secure-only session cookie makes it more difficult for network traffic
  485. sniffers to hijack user sessions.
  486. * **security.W013**: You have :mod:`django.contrib.sessions` in your
  487. :setting:`INSTALLED_APPS`, but you have not set
  488. :setting:`SESSION_COOKIE_HTTPONLY` to ``True``. Using an ``HttpOnly`` session
  489. cookie makes it more difficult for cross-site scripting attacks to hijack user
  490. sessions.
  491. * **security.W014**: You have
  492. :class:`django.contrib.sessions.middleware.SessionMiddleware` in your
  493. :setting:`MIDDLEWARE`/:setting:`MIDDLEWARE_CLASSES`, but you have not set
  494. :setting:`SESSION_COOKIE_HTTPONLY` to ``True``. Using an ``HttpOnly`` session
  495. cookie makes it more difficult for cross-site scripting attacks to hijack user
  496. sessions.
  497. * **security.W015**: :setting:`SESSION_COOKIE_HTTPONLY` is not set to ``True``.
  498. Using an ``HttpOnly`` session cookie makes it more difficult for cross-site
  499. scripting attacks to hijack user sessions.
  500. * **security.W016**: :setting:`CSRF_COOKIE_SECURE` is not set to ``True``.
  501. Using a secure-only CSRF cookie makes it more difficult for network traffic
  502. sniffers to steal the CSRF token.
  503. * **security.W017**: :setting:`CSRF_COOKIE_HTTPONLY` is not set to ``True``.
  504. Using an ``HttpOnly`` CSRF cookie makes it more difficult for cross-site
  505. scripting attacks to steal the CSRF token.
  506. * **security.W018**: You should not have :setting:`DEBUG` set to ``True`` in
  507. deployment.
  508. * **security.W019**: You have
  509. :class:`django.middleware.clickjacking.XFrameOptionsMiddleware` in your
  510. :setting:`MIDDLEWARE`/:setting:`MIDDLEWARE_CLASSES`, but :setting:`X_FRAME_OPTIONS` is not set to
  511. ``'DENY'``. The default is ``'SAMEORIGIN'``, but unless there is a good reason
  512. for your site to serve other parts of itself in a frame, you should change
  513. it to ``'DENY'``.
  514. * **security.W020**: :setting:`ALLOWED_HOSTS` must not be empty in deployment.
  515. Sites
  516. -----
  517. The following checks are performed on any model using a
  518. :class:`~django.contrib.sites.managers.CurrentSiteManager`:
  519. * **sites.E001**: ``CurrentSiteManager`` could not find a field named
  520. ``<field name>``.
  521. * **sites.E002**: ``CurrentSiteManager`` cannot use ``<field>`` as it is not a
  522. foreign key or a many-to-many field.
  523. Database
  524. --------
  525. MySQL
  526. ~~~~~
  527. If you're using MySQL, the following checks will be performed:
  528. * **mysql.E001**: MySQL does not allow unique ``CharField``\s to have a
  529. ``max_length`` > 255.
  530. * **mysql.W002**: MySQL Strict Mode is not set for database connection
  531. '<alias>'. See also :ref:`mysql-sql-mode`.
  532. Templates
  533. ---------
  534. The following checks verify that your :setting:`TEMPLATES` setting is correctly
  535. configured:
  536. * **templates.E001**: You have ``'APP_DIRS': True`` in your
  537. :setting:`TEMPLATES` but also specify ``'loaders'`` in ``OPTIONS``. Either
  538. remove ``APP_DIRS`` or remove the ``'loaders'`` option.
  539. * **templates.E002**: ``string_if_invalid`` in :setting:`TEMPLATES`
  540. :setting:`OPTIONS <TEMPLATES-OPTIONS>` must be a string but got: ``{value}``
  541. (``{type}``).
  542. Caches
  543. ------
  544. The following checks verify that your :setting:`CACHES` setting is correctly
  545. configured:
  546. * **caches.E001**: You must define a ``'default'`` cache in your
  547. :setting:`CACHES` setting.
  548. URLs
  549. ----
  550. The following checks are performed on your URL configuration:
  551. * **urls.W001**: Your URL pattern ``<pattern>`` uses
  552. :func:`~django.conf.urls.include` with a ``regex`` ending with a
  553. ``$``. Remove the dollar from the ``regex`` to avoid problems
  554. including URLs.
  555. * **urls.W002**: Your URL pattern ``<pattern>`` has a ``regex``
  556. beginning with a ``/``. Remove this slash as it is unnecessary.
  557. * **urls.W003**: Your URL pattern ``<pattern>`` has a ``name``
  558. including a ``:``. Remove the colon, to avoid ambiguous namespace
  559. references.
  560. * **urls.E004**: Your URL pattern ``<pattern>`` is invalid. Ensure that
  561. ``urlpatterns`` is a list of :func:`~django.conf.urls.url()` instances.