checks.txt 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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 a ``__str__()`` method.
  37. The method is used while reporting all messages and its result precedes the
  38. 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. .. _system-check-builtin-tags:
  54. Builtin tags
  55. ============
  56. Django's system checks are organized using the following tags:
  57. * ``admin``: Checks of any admin site declarations.
  58. * ``caches``: Checks cache related configuration.
  59. * ``compatibility``: Flags potential problems with version upgrades.
  60. * ``database``: Checks database-related configuration issues. Database checks
  61. are not run by default because they do more than static code analysis as
  62. regular checks do. They are only run by the :djadmin:`migrate` command or if
  63. you specify the ``database`` tag when calling the :djadmin:`check` command.
  64. * ``models``: Checks of model, field, and manager definitions.
  65. * ``security``: Checks security related configuration.
  66. * ``signals``: Checks on signal declarations and handler registrations.
  67. * ``staticfiles``: Checks :mod:`django.contrib.staticfiles` configuration.
  68. * ``templates``: Checks template related configuration.
  69. * ``urls``: Checks URL configuration.
  70. Some checks may be registered with multiple tags.
  71. Core system checks
  72. ==================
  73. Backwards compatibility
  74. -----------------------
  75. Compatibility checks warn of potential problems that might occur after
  76. upgrading Django.
  77. * **2_0.W001**: Your URL pattern ``<pattern>`` has a ``route`` that contains
  78. ``(?P<``, begins with a ``^``, or ends with a ``$``. This was likely an
  79. oversight when migrating from ``url()`` to :func:`~django.urls.path`.
  80. Caches
  81. ------
  82. The following checks verify that your :setting:`CACHES` setting is correctly
  83. configured:
  84. * **caches.E001**: You must define a ``'default'`` cache in your
  85. :setting:`CACHES` setting.
  86. Database
  87. --------
  88. MySQL
  89. ~~~~~
  90. If you're using MySQL, the following checks will be performed:
  91. * **mysql.E001**: MySQL does not allow unique ``CharField``\s to have a
  92. ``max_length`` > 255.
  93. * **mysql.W002**: MySQL Strict Mode is not set for database connection
  94. '<alias>'. See also :ref:`mysql-sql-mode`.
  95. Model fields
  96. ------------
  97. * **fields.E001**: Field names must not end with an underscore.
  98. * **fields.E002**: Field names must not contain ``"__"``.
  99. * **fields.E003**: ``pk`` is a reserved word that cannot be used as a field
  100. name.
  101. * **fields.E004**: ``choices`` must be an iterable (e.g., a list or tuple).
  102. * **fields.E005**: ``choices`` must be an iterable returning ``(actual value,
  103. human readable name)`` tuples.
  104. * **fields.E006**: ``db_index`` must be ``None``, ``True`` or ``False``.
  105. * **fields.E007**: Primary keys must not have ``null=True``.
  106. * **fields.E008**: All ``validators`` must be callable.
  107. * **fields.E100**: ``AutoField``\s must set primary_key=True.
  108. * **fields.E110**: ``BooleanField``\s do not accept null values. *This check
  109. appeared before support for null values was added in Django 2.1.*
  110. * **fields.E120**: ``CharField``\s must define a ``max_length`` attribute.
  111. * **fields.E121**: ``max_length`` must be a positive integer.
  112. * **fields.W122**: ``max_length`` is ignored when used with ``IntegerField``.
  113. * **fields.E130**: ``DecimalField``\s must define a ``decimal_places`` attribute.
  114. * **fields.E131**: ``decimal_places`` must be a non-negative integer.
  115. * **fields.E132**: ``DecimalField``\s must define a ``max_digits`` attribute.
  116. * **fields.E133**: ``max_digits`` must be a non-negative integer.
  117. * **fields.E134**: ``max_digits`` must be greater or equal to ``decimal_places``.
  118. * **fields.E140**: ``FilePathField``\s must have either ``allow_files`` or
  119. ``allow_folders`` set to True.
  120. * **fields.E150**: ``GenericIPAddressField``\s cannot accept blank values if
  121. null values are not allowed, as blank values are stored as nulls.
  122. * **fields.E160**: The options ``auto_now``, ``auto_now_add``, and ``default``
  123. are mutually exclusive. Only one of these options may be present.
  124. * **fields.W161**: Fixed default value provided.
  125. * **fields.W162**: ``<database>`` does not support a database index on
  126. ``<field data type>`` columns.
  127. * **fields.E900**: ``IPAddressField`` has been removed except for support in
  128. historical migrations.
  129. * **fields.W900**: ``IPAddressField`` has been deprecated. Support for it
  130. (except in historical migrations) will be removed in Django 1.9. *This check
  131. appeared in Django 1.7 and 1.8*.
  132. * **fields.W901**: ``CommaSeparatedIntegerField`` has been deprecated. Support
  133. for it (except in historical migrations) will be removed in Django 2.0. *This
  134. check appeared in Django 1.10 and 1.11*.
  135. * **fields.E901**: ``CommaSeparatedIntegerField`` is removed except for support
  136. in historical migrations.
  137. File fields
  138. ~~~~~~~~~~~
  139. * **fields.E200**: ``unique`` is not a valid argument for a ``FileField``.
  140. *This check is removed in Django 1.11*.
  141. * **fields.E201**: ``primary_key`` is not a valid argument for a ``FileField``.
  142. * **fields.E202**: ``FileField``’s ``upload_to`` argument must be a relative
  143. path, not an absolute path.
  144. * **fields.E210**: Cannot use ``ImageField`` because Pillow is not installed.
  145. Related fields
  146. ~~~~~~~~~~~~~~
  147. * **fields.E300**: Field defines a relation with model ``<model>``, which is
  148. either not installed, or is abstract.
  149. * **fields.E301**: Field defines a relation with the model ``<model>`` which
  150. has been swapped out.
  151. * **fields.E302**: Accessor for field ``<field name>`` clashes with field
  152. ``<field name>``.
  153. * **fields.E303**: Reverse query name for field ``<field name>`` clashes with
  154. field ``<field name>``.
  155. * **fields.E304**: Field name ``<field name>`` clashes with accessor for
  156. ``<field name>``.
  157. * **fields.E305**: Field name ``<field name>`` clashes with reverse query name
  158. for ``<field name>``.
  159. * **fields.E306**: Related name must be a valid Python identifier or end with
  160. a ``'+'``.
  161. * **fields.E307**: The field ``<app label>.<model>.<field name>`` was declared
  162. with a lazy reference to ``<app label>.<model>``, but app ``<app label>``
  163. isn't installed or doesn't provide model ``<model>``.
  164. * **fields.E308**: Reverse query name ``<related query name>`` must not end
  165. with an underscore.
  166. * **fields.E309**: Reverse query name ``<related query name>`` must not contain
  167. ``'__'``.
  168. * **fields.E310**: No subset of the fields ``<field1>``, ``<field2>``, ... on
  169. model ``<model>`` is unique. Add ``unique=True`` on any of those fields or
  170. add at least a subset of them to a unique_together constraint.
  171. * **fields.E311**: ``<model>`` must set ``unique=True`` because it is
  172. referenced by a ``ForeignKey``.
  173. * **fields.E312**: The ``to_field`` ``<field name>`` doesn't exist on the
  174. related model ``<app label>.<model>``.
  175. * **fields.E320**: Field specifies ``on_delete=SET_NULL``, but cannot be null.
  176. * **fields.E321**: The field specifies ``on_delete=SET_DEFAULT``, but has no
  177. default value.
  178. * **fields.E330**: ``ManyToManyField``\s cannot be unique.
  179. * **fields.E331**: Field specifies a many-to-many relation through model
  180. ``<model>``, which has not been installed.
  181. * **fields.E332**: Many-to-many fields with intermediate tables must not be
  182. symmetrical.
  183. * **fields.E333**: The model is used as an intermediate model by ``<model>``,
  184. but it has more than two foreign keys to ``<model>``, which is ambiguous.
  185. You must specify which two foreign keys Django should use via the
  186. ``through_fields`` keyword argument.
  187. * **fields.E334**: The model is used as an intermediate model by ``<model>``,
  188. but it has more than one foreign key from ``<model>``, which is ambiguous.
  189. You must specify which foreign key Django should use via the
  190. ``through_fields`` keyword argument.
  191. * **fields.E335**: The model is used as an intermediate model by ``<model>``,
  192. but it has more than one foreign key to ``<model>``, which is ambiguous.
  193. You must specify which foreign key Django should use via the
  194. ``through_fields`` keyword argument.
  195. * **fields.E336**: The model is used as an intermediary model by ``<model>``,
  196. but it does not have foreign key to ``<model>`` or ``<model>``.
  197. * **fields.E337**: Field specifies ``through_fields`` but does not provide the
  198. names of the two link fields that should be used for the relation through
  199. ``<model>``.
  200. * **fields.E338**: The intermediary model ``<through model>`` has no field
  201. ``<field name>``.
  202. * **fields.E339**: ``<model>.<field name>`` is not a foreign key to ``<model>``.
  203. * **fields.E340**: The field's intermediary table ``<table name>`` clashes with
  204. the table name of ``<model>``/``<model>.<field name>``.
  205. * **fields.W340**: ``null`` has no effect on ``ManyToManyField``.
  206. * **fields.W341**: ``ManyToManyField`` does not support ``validators``.
  207. * **fields.W342**: Setting ``unique=True`` on a ``ForeignKey`` has the same
  208. effect as using a ``OneToOneField``.
  209. * **fields.W343**: ``limit_choices_to`` has no effect on ``ManyToManyField``
  210. with a ``through`` model.
  211. Models
  212. ------
  213. * **models.E001**: ``<swappable>`` is not of the form ``app_label.app_name``.
  214. * **models.E002**: ``<SETTING>`` references ``<model>``, which has not been
  215. installed, or is abstract.
  216. * **models.E003**: The model has two many-to-many relations through the
  217. intermediate model ``<app_label>.<model>``.
  218. * **models.E004**: ``id`` can only be used as a field name if the field also
  219. sets ``primary_key=True``.
  220. * **models.E005**: The field ``<field name>`` from parent model ``<model>``
  221. clashes with the field ``<field name>`` from parent model ``<model>``.
  222. * **models.E006**: The field clashes with the field ``<field name>`` from model
  223. ``<model>``.
  224. * **models.E007**: Field ``<field name>`` has column name ``<column name>``
  225. that is used by another field.
  226. * **models.E008**: ``index_together`` must be a list or tuple.
  227. * **models.E009**: All ``index_together`` elements must be lists or tuples.
  228. * **models.E010**: ``unique_together`` must be a list or tuple.
  229. * **models.E011**: All ``unique_together`` elements must be lists or tuples.
  230. * **models.E012**: ``indexes/index_together/unique_together`` refers to the
  231. nonexistent field ``<field name>``.
  232. * **models.E013**: ``indexes/index_together/unique_together`` refers to a
  233. ``ManyToManyField`` ``<field name>``, but ``ManyToManyField``\s are not
  234. supported for that option.
  235. * **models.E014**: ``ordering`` must be a tuple or list (even if you want to
  236. order by only one field).
  237. * **models.E015**: ``ordering`` refers to the nonexistent field
  238. ``<field name>``.
  239. * **models.E016**: ``indexes/index_together/unique_together`` refers to field
  240. ``<field_name>`` which is not local to model ``<model>``.
  241. * **models.E017**: Proxy model ``<model>`` contains model fields.
  242. * **models.E018**: Autogenerated column name too long for field ``<field>``.
  243. Maximum length is ``<maximum length>`` for database ``<alias>``.
  244. * **models.E019**: Autogenerated column name too long for M2M field
  245. ``<M2M field>``. Maximum length is ``<maximum length>`` for database
  246. ``<alias>``.
  247. * **models.E020**: The ``<model>.check()`` class method is currently overridden.
  248. * **models.E021**: ``ordering`` and ``order_with_respect_to`` cannot be used
  249. together.
  250. * **models.E022**: ``<function>`` contains a lazy reference to
  251. ``<app label>.<model>``, but app ``<app label>`` isn't installed or
  252. doesn't provide model ``<model>``.
  253. * **models.E023**: The model name ``<model>`` cannot start or end with an
  254. underscore as it collides with the query lookup syntax.
  255. * **models.E024**: The model name ``<model>`` cannot contain double underscores
  256. as it collides with the query lookup syntax.
  257. * **models.E025**: The property ``<property name>`` clashes with a related
  258. field accessor.
  259. * **models.E026**: The model cannot have more than one field with
  260. ``primary_key=True``.
  261. Security
  262. --------
  263. The security checks do not make your site secure. They do not audit code, do
  264. intrusion detection, or do anything particularly complex. Rather, they help
  265. perform an automated, low-hanging-fruit checklist. They help you remember the
  266. simple things that improve your site's security.
  267. Some of these checks may not be appropriate for your particular deployment
  268. configuration. For instance, if you do your HTTP to HTTPS redirection in a load
  269. balancer, it'd be irritating to be constantly warned about not having enabled
  270. :setting:`SECURE_SSL_REDIRECT`. Use :setting:`SILENCED_SYSTEM_CHECKS` to
  271. silence unneeded checks.
  272. The following checks are run if you use the :option:`check --deploy` option:
  273. * **security.W001**: You do not have
  274. :class:`django.middleware.security.SecurityMiddleware` in your
  275. :setting:`MIDDLEWARE` so the :setting:`SECURE_HSTS_SECONDS`,
  276. :setting:`SECURE_CONTENT_TYPE_NOSNIFF`, :setting:`SECURE_BROWSER_XSS_FILTER`,
  277. and :setting:`SECURE_SSL_REDIRECT` settings will have no effect.
  278. * **security.W002**: You do not have
  279. :class:`django.middleware.clickjacking.XFrameOptionsMiddleware` in your
  280. :setting:`MIDDLEWARE`, so your pages will not be served with an
  281. ``'x-frame-options'`` header. Unless there is a good reason for your
  282. site to be served in a frame, you should consider enabling this
  283. header to help prevent clickjacking attacks.
  284. * **security.W003**: You don't appear to be using Django's built-in cross-site
  285. request forgery protection via the middleware
  286. (:class:`django.middleware.csrf.CsrfViewMiddleware` is not in your
  287. :setting:`MIDDLEWARE`). Enabling the middleware is the safest
  288. approach to ensure you don't leave any holes.
  289. * **security.W004**: You have not set a value for the
  290. :setting:`SECURE_HSTS_SECONDS` setting. If your entire site is served only
  291. over SSL, you may want to consider setting a value and enabling :ref:`HTTP
  292. Strict Transport Security <http-strict-transport-security>`. Be sure to read
  293. the documentation first; enabling HSTS carelessly can cause serious,
  294. irreversible problems.
  295. * **security.W005**: You have not set the
  296. :setting:`SECURE_HSTS_INCLUDE_SUBDOMAINS` setting to ``True``. Without this,
  297. your site is potentially vulnerable to attack via an insecure connection to a
  298. subdomain. Only set this to ``True`` if you are certain that all subdomains of
  299. your domain should be served exclusively via SSL.
  300. * **security.W006**: Your :setting:`SECURE_CONTENT_TYPE_NOSNIFF` setting is not
  301. set to ``True``, so your pages will not be served with an
  302. ``'x-content-type-options: nosniff'`` header. You should consider enabling
  303. this header to prevent the browser from identifying content types incorrectly.
  304. * **security.W007**: Your :setting:`SECURE_BROWSER_XSS_FILTER` setting is not
  305. set to ``True``, so your pages will not be served with an
  306. ``'x-xss-protection: 1; mode=block'`` header. You should consider enabling
  307. this header to activate the browser's XSS filtering and help prevent XSS
  308. attacks.
  309. * **security.W008**: Your :setting:`SECURE_SSL_REDIRECT` setting is not set to
  310. ``True``. Unless your site should be available over both SSL and non-SSL
  311. connections, you may want to either set this setting to ``True`` or configure
  312. a load balancer or reverse-proxy server to redirect all connections to HTTPS.
  313. * **security.W009**: Your :setting:`SECRET_KEY` has less than 50 characters or
  314. less than 5 unique characters. Please generate a long and random
  315. ``SECRET_KEY``, otherwise many of Django's security-critical features will be
  316. vulnerable to attack.
  317. * **security.W010**: You have :mod:`django.contrib.sessions` in your
  318. :setting:`INSTALLED_APPS` but you have not set
  319. :setting:`SESSION_COOKIE_SECURE` to ``True``. Using a secure-only session
  320. cookie makes it more difficult for network traffic sniffers to hijack user
  321. sessions.
  322. * **security.W011**: You have
  323. :class:`django.contrib.sessions.middleware.SessionMiddleware` in your
  324. :setting:`MIDDLEWARE`, but you have not set :setting:`SESSION_COOKIE_SECURE`
  325. to ``True``. Using a secure-only session cookie makes it more difficult for
  326. network traffic sniffers to hijack user sessions.
  327. * **security.W012**: :setting:`SESSION_COOKIE_SECURE` is not set to ``True``.
  328. Using a secure-only session cookie makes it more difficult for network traffic
  329. sniffers to hijack user sessions.
  330. * **security.W013**: You have :mod:`django.contrib.sessions` in your
  331. :setting:`INSTALLED_APPS`, but you have not set
  332. :setting:`SESSION_COOKIE_HTTPONLY` to ``True``. Using an ``HttpOnly`` session
  333. cookie makes it more difficult for cross-site scripting attacks to hijack user
  334. sessions.
  335. * **security.W014**: You have
  336. :class:`django.contrib.sessions.middleware.SessionMiddleware` in your
  337. :setting:`MIDDLEWARE`, but you have not set :setting:`SESSION_COOKIE_HTTPONLY`
  338. to ``True``. Using an ``HttpOnly`` session cookie makes it more difficult for
  339. cross-site scripting attacks to hijack user sessions.
  340. * **security.W015**: :setting:`SESSION_COOKIE_HTTPONLY` is not set to ``True``.
  341. Using an ``HttpOnly`` session cookie makes it more difficult for cross-site
  342. scripting attacks to hijack user sessions.
  343. * **security.W016**: :setting:`CSRF_COOKIE_SECURE` is not set to ``True``.
  344. Using a secure-only CSRF cookie makes it more difficult for network traffic
  345. sniffers to steal the CSRF token.
  346. * **security.W017**: :setting:`CSRF_COOKIE_HTTPONLY` is not set to ``True``.
  347. Using an ``HttpOnly`` CSRF cookie makes it more difficult for cross-site
  348. scripting attacks to steal the CSRF token. *This check is removed in Django
  349. 1.11 as the* :setting:`CSRF_COOKIE_HTTPONLY` *setting offers no pratical
  350. benefit.*
  351. * **security.W018**: You should not have :setting:`DEBUG` set to ``True`` in
  352. deployment.
  353. * **security.W019**: You have
  354. :class:`django.middleware.clickjacking.XFrameOptionsMiddleware` in your
  355. :setting:`MIDDLEWARE`, but :setting:`X_FRAME_OPTIONS` is not set to
  356. ``'DENY'``. The default is ``'SAMEORIGIN'``, but unless there is a good reason
  357. for your site to serve other parts of itself in a frame, you should change
  358. it to ``'DENY'``.
  359. * **security.W020**: :setting:`ALLOWED_HOSTS` must not be empty in deployment.
  360. * **security.W021**: You have not set the
  361. :setting:`SECURE_HSTS_PRELOAD` setting to ``True``. Without this, your site
  362. cannot be submitted to the browser preload list.
  363. Signals
  364. -------
  365. * **signals.E001**: ``<handler>`` was connected to the ``<signal>`` signal with
  366. a lazy reference to the sender ``<app label>.<model>``, but app ``<app label>``
  367. isn't installed or doesn't provide model ``<model>``.
  368. Templates
  369. ---------
  370. The following checks verify that your :setting:`TEMPLATES` setting is correctly
  371. configured:
  372. * **templates.E001**: You have ``'APP_DIRS': True`` in your
  373. :setting:`TEMPLATES` but also specify ``'loaders'`` in ``OPTIONS``. Either
  374. remove ``APP_DIRS`` or remove the ``'loaders'`` option.
  375. * **templates.E002**: ``string_if_invalid`` in :setting:`TEMPLATES`
  376. :setting:`OPTIONS <TEMPLATES-OPTIONS>` must be a string but got: ``{value}``
  377. (``{type}``).
  378. URLs
  379. ----
  380. The following checks are performed on your URL configuration:
  381. * **urls.W001**: Your URL pattern ``<pattern>`` uses
  382. :func:`~django.urls.include` with a ``route`` ending with a ``$``. Remove the
  383. dollar from the ``route`` to avoid problems including URLs.
  384. * **urls.W002**: Your URL pattern ``<pattern>`` has a ``route`` beginning with
  385. a ``/``. Remove this slash as it is unnecessary. If this pattern is targeted
  386. in an :func:`~django.urls.include`, ensure the :func:`~django.urls.include`
  387. pattern has a trailing ``/``.
  388. * **urls.W003**: Your URL pattern ``<pattern>`` has a ``name``
  389. including a ``:``. Remove the colon, to avoid ambiguous namespace
  390. references.
  391. * **urls.E004**: Your URL pattern ``<pattern>`` is invalid. Ensure that
  392. ``urlpatterns`` is a list of :func:`~django.urls.path` and/or
  393. :func:`~django.urls.re_path` instances.
  394. * **urls.W005**: URL namespace ``<namespace>`` isn't unique. You may not be
  395. able to reverse all URLs in this namespace.
  396. * **urls.E006**: The :setting:`MEDIA_URL`/ :setting:`STATIC_URL` setting must
  397. end with a slash.
  398. ``contrib`` app checks
  399. ======================
  400. ``admin``
  401. ---------
  402. Admin checks are all performed as part of the ``admin`` tag.
  403. The following checks are performed on any
  404. :class:`~django.contrib.admin.ModelAdmin` (or subclass) that is registered
  405. with the admin site:
  406. * **admin.E001**: The value of ``raw_id_fields`` must be a list or tuple.
  407. * **admin.E002**: The value of ``raw_id_fields[n]`` refers to ``<field name>``,
  408. which is not an attribute of ``<model>``.
  409. * **admin.E003**: The value of ``raw_id_fields[n]`` must be a foreign key or
  410. a many-to-many field.
  411. * **admin.E004**: The value of ``fields`` must be a list or tuple.
  412. * **admin.E005**: Both ``fieldsets`` and ``fields`` are specified.
  413. * **admin.E006**: The value of ``fields`` contains duplicate field(s).
  414. * **admin.E007**: The value of ``fieldsets`` must be a list or tuple.
  415. * **admin.E008**: The value of ``fieldsets[n]`` must be a list or tuple.
  416. * **admin.E009**: The value of ``fieldsets[n]`` must be of length 2.
  417. * **admin.E010**: The value of ``fieldsets[n][1]`` must be a dictionary.
  418. * **admin.E011**: The value of ``fieldsets[n][1]`` must contain the key
  419. ``fields``.
  420. * **admin.E012**: There are duplicate field(s) in ``fieldsets[n][1]``.
  421. * **admin.E013**: ``fields[n]/fieldsets[n][m]`` cannot include the
  422. ``ManyToManyField`` ``<field name>``, because that field manually specifies a
  423. relationship model.
  424. * **admin.E014**: The value of ``exclude`` must be a list or tuple.
  425. * **admin.E015**: The value of ``exclude`` contains duplicate field(s).
  426. * **admin.E016**: The value of ``form`` must inherit from ``BaseModelForm``.
  427. * **admin.E017**: The value of ``filter_vertical`` must be a list or tuple.
  428. * **admin.E018**: The value of ``filter_horizontal`` must be a list or tuple.
  429. * **admin.E019**: The value of ``filter_vertical[n]/filter_vertical[n]`` refers
  430. to ``<field name>``, which is not an attribute of ``<model>``.
  431. * **admin.E020**: The value of ``filter_vertical[n]/filter_vertical[n]`` must
  432. be a many-to-many field.
  433. * **admin.E021**: The value of ``radio_fields`` must be a dictionary.
  434. * **admin.E022**: The value of ``radio_fields`` refers to ``<field name>``,
  435. which is not an attribute of ``<model>``.
  436. * **admin.E023**: The value of ``radio_fields`` refers to ``<field name>``,
  437. which is not a ``ForeignKey``, and does not have a ``choices`` definition.
  438. * **admin.E024**: The value of ``radio_fields[<field name>]`` must be either
  439. ``admin.HORIZONTAL`` or ``admin.VERTICAL``.
  440. * **admin.E025**: The value of ``view_on_site`` must be either a callable or a
  441. boolean value.
  442. * **admin.E026**: The value of ``prepopulated_fields`` must be a dictionary.
  443. * **admin.E027**: The value of ``prepopulated_fields`` refers to
  444. ``<field name>``, which is not an attribute of ``<model>``.
  445. * **admin.E028**: The value of ``prepopulated_fields`` refers to
  446. ``<field name>``, which must not be a ``DateTimeField``, a ``ForeignKey``,
  447. a ``OneToOneField``, or a ``ManyToManyField`` field.
  448. * **admin.E029**: The value of ``prepopulated_fields[<field name>]`` must be a
  449. list or tuple.
  450. * **admin.E030**: The value of ``prepopulated_fields`` refers to
  451. ``<field name>``, which is not an attribute of ``<model>``.
  452. * **admin.E031**: The value of ``ordering`` must be a list or tuple.
  453. * **admin.E032**: The value of ``ordering`` has the random ordering marker
  454. ``?``, but contains other fields as well.
  455. * **admin.E033**: The value of ``ordering`` refers to ``<field name>``, which
  456. is not an attribute of ``<model>``.
  457. * **admin.E034**: The value of ``readonly_fields`` must be a list or tuple.
  458. * **admin.E035**: The value of ``readonly_fields[n]`` is not a callable, an
  459. attribute of ``<ModelAdmin class>``, or an attribute of ``<model>``.
  460. * **admin.E036**: The value of ``autocomplete_fields`` must be a list or tuple.
  461. * **admin.E037**: The value of ``autocomplete_fields[n]`` refers to
  462. ``<field name>``, which is not an attribute of ``<model>``.
  463. * **admin.E038**: The value of ``autocomplete_fields[n]`` must be a foreign
  464. key or a many-to-many field.
  465. * **admin.E039**: An admin for model ``<model>`` has to be registered to be
  466. referenced by ``<modeladmin>.autocomplete_fields``.
  467. * **admin.E040**: ``<modeladmin>`` must define ``search_fields``, because
  468. it's referenced by ``<other_modeladmin>.autocomplete_fields``.
  469. ``ModelAdmin``
  470. ~~~~~~~~~~~~~~
  471. The following checks are performed on any
  472. :class:`~django.contrib.admin.ModelAdmin` that is registered
  473. with the admin site:
  474. * **admin.E101**: The value of ``save_as`` must be a boolean.
  475. * **admin.E102**: The value of ``save_on_top`` must be a boolean.
  476. * **admin.E103**: The value of ``inlines`` must be a list or tuple.
  477. * **admin.E104**: ``<InlineModelAdmin class>`` must inherit from
  478. ``InlineModelAdmin``.
  479. * **admin.E105**: ``<InlineModelAdmin class>`` must have a ``model`` attribute.
  480. * **admin.E106**: The value of ``<InlineModelAdmin class>.model`` must be a
  481. ``Model``.
  482. * **admin.E107**: The value of ``list_display`` must be a list or tuple.
  483. * **admin.E108**: The value of ``list_display[n]`` refers to ``<label>``,
  484. which is not a callable, an attribute of ``<ModelAdmin class>``, or an
  485. attribute or method on ``<model>``.
  486. * **admin.E109**: The value of ``list_display[n]`` must not be a
  487. ``ManyToManyField`` field.
  488. * **admin.E110**: The value of ``list_display_links`` must be a list, a tuple,
  489. or ``None``.
  490. * **admin.E111**: The value of ``list_display_links[n]`` refers to ``<label>``,
  491. which is not defined in ``list_display``.
  492. * **admin.E112**: The value of ``list_filter`` must be a list or tuple.
  493. * **admin.E113**: The value of ``list_filter[n]`` must inherit from
  494. ``ListFilter``.
  495. * **admin.E114**: The value of ``list_filter[n]`` must not inherit from
  496. ``FieldListFilter``.
  497. * **admin.E115**: The value of ``list_filter[n][1]`` must inherit from
  498. ``FieldListFilter``.
  499. * **admin.E116**: The value of ``list_filter[n]`` refers to ``<label>``,
  500. which does not refer to a Field.
  501. * **admin.E117**: The value of ``list_select_related`` must be a boolean,
  502. tuple or list.
  503. * **admin.E118**: The value of ``list_per_page`` must be an integer.
  504. * **admin.E119**: The value of ``list_max_show_all`` must be an integer.
  505. * **admin.E120**: The value of ``list_editable`` must be a list or tuple.
  506. * **admin.E121**: The value of ``list_editable[n]`` refers to ``<label>``,
  507. which is not an attribute of ``<model>``.
  508. * **admin.E122**: The value of ``list_editable[n]`` refers to ``<label>``,
  509. which is not contained in ``list_display``.
  510. * **admin.E123**: The value of ``list_editable[n]`` cannot be in both
  511. ``list_editable`` and ``list_display_links``.
  512. * **admin.E124**: The value of ``list_editable[n]`` refers to the first field
  513. in ``list_display`` (``<label>``), which cannot be used unless
  514. ``list_display_links`` is set.
  515. * **admin.E125**: The value of ``list_editable[n]`` refers to ``<field name>``,
  516. which is not editable through the admin.
  517. * **admin.E126**: The value of ``search_fields`` must be a list or tuple.
  518. * **admin.E127**: The value of ``date_hierarchy`` refers to ``<field name>``,
  519. which does not refer to a Field.
  520. * **admin.E128**: The value of ``date_hierarchy`` must be a ``DateField`` or
  521. ``DateTimeField``.
  522. ``InlineModelAdmin``
  523. ~~~~~~~~~~~~~~~~~~~~
  524. The following checks are performed on any
  525. :class:`~django.contrib.admin.InlineModelAdmin` that is registered as an
  526. inline on a :class:`~django.contrib.admin.ModelAdmin`.
  527. * **admin.E201**: Cannot exclude the field ``<field name>``, because it is the
  528. foreign key to the parent model ``<app_label>.<model>``.
  529. * **admin.E202**: ``<model>`` has no ``ForeignKey`` to ``<parent model>``./
  530. ``<model>`` has more than one ``ForeignKey`` to ``<parent model>``.
  531. * **admin.E203**: The value of ``extra`` must be an integer.
  532. * **admin.E204**: The value of ``max_num`` must be an integer.
  533. * **admin.E205**: The value of ``min_num`` must be an integer.
  534. * **admin.E206**: The value of ``formset`` must inherit from
  535. ``BaseModelFormSet``.
  536. ``GenericInlineModelAdmin``
  537. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  538. The following checks are performed on any
  539. :class:`~django.contrib.contenttypes.admin.GenericInlineModelAdmin` that is
  540. registered as an inline on a :class:`~django.contrib.admin.ModelAdmin`.
  541. * **admin.E301**: ``'ct_field'`` references ``<label>``, which is not a field
  542. on ``<model>``.
  543. * **admin.E302**: ``'ct_fk_field'`` references ``<label>``, which is not a
  544. field on ``<model>``.
  545. * **admin.E303**: ``<model>`` has no ``GenericForeignKey``.
  546. * **admin.E304**: ``<model>`` has no ``GenericForeignKey`` using content type
  547. field ``<field name>`` and object ID field ``<field name>``.
  548. ``AdminSite``
  549. ~~~~~~~~~~~~~
  550. The following checks are performed on the default
  551. :class:`~django.contrib.admin.AdminSite`:
  552. * **admin.E401**: :mod:`django.contrib.contenttypes` must be in
  553. :setting:`INSTALLED_APPS` in order to use the admin application.
  554. * **admin.E402**: :mod:`django.contrib.auth.context_processors.auth`
  555. must be in :setting:`TEMPLATES` in order to use the admin application.
  556. ``auth``
  557. --------
  558. * **auth.E001**: ``REQUIRED_FIELDS`` must be a list or tuple.
  559. * **auth.E002**: The field named as the ``USERNAME_FIELD`` for a custom user
  560. model must not be included in ``REQUIRED_FIELDS``.
  561. * **auth.E003**: ``<field>`` must be unique because it is named as the
  562. ``USERNAME_FIELD``.
  563. * **auth.W004**: ``<field>`` is named as the ``USERNAME_FIELD``, but it is not
  564. unique.
  565. * **auth.E005**: The permission codenamed ``<codename>`` clashes with a builtin
  566. permission for model ``<model>``.
  567. * **auth.E006**: The permission codenamed ``<codename>`` is duplicated for model
  568. ``<model>``.
  569. * **auth.E007**: The :attr:`verbose_name
  570. <django.db.models.Options.verbose_name>` of model ``<model>`` must be at most
  571. 244 characters for its builtin permission names
  572. to be at most 255 characters.
  573. * **auth.E008**: The permission named ``<name>`` of model ``<model>`` is longer
  574. than 255 characters.
  575. * **auth.C009**: ``<User model>.is_anonymous`` must be an attribute or property
  576. rather than a method. Ignoring this is a security issue as anonymous users
  577. will be treated as authenticated!
  578. * **auth.C010**: ``<User model>.is_authenticated`` must be an attribute or
  579. property rather than a method. Ignoring this is a security issue as anonymous
  580. users will be treated as authenticated!
  581. ``contenttypes``
  582. ----------------
  583. The following checks are performed when a model contains a
  584. :class:`~django.contrib.contenttypes.fields.GenericForeignKey` or
  585. :class:`~django.contrib.contenttypes.fields.GenericRelation`:
  586. * **contenttypes.E001**: The ``GenericForeignKey`` object ID references the
  587. nonexistent field ``<field>``.
  588. * **contenttypes.E002**: The ``GenericForeignKey`` content type references the
  589. nonexistent field ``<field>``.
  590. * **contenttypes.E003**: ``<field>`` is not a ``ForeignKey``.
  591. * **contenttypes.E004**: ``<field>`` is not a ``ForeignKey`` to
  592. ``contenttypes.ContentType``.
  593. * **contenttypes.E005**: Model names must be at most 100 characters.
  594. ``postgres``
  595. ------------
  596. The following checks are performed on :mod:`django.contrib.postgres` model
  597. fields:
  598. * **postgres.E001**: Base field for array has errors: ...
  599. * **postgres.E002**: Base field for array cannot be a related field.
  600. * **postgres.E003**: ``<field>`` default should be a callable instead of an
  601. instance so that it's not shared between all field instances.
  602. ``sites``
  603. ---------
  604. The following checks are performed on any model using a
  605. :class:`~django.contrib.sites.managers.CurrentSiteManager`:
  606. * **sites.E001**: ``CurrentSiteManager`` could not find a field named
  607. ``<field name>``.
  608. * **sites.E002**: ``CurrentSiteManager`` cannot use ``<field>`` as it is not a
  609. foreign key or a many-to-many field.
  610. ``staticfiles``
  611. ---------------
  612. The following checks verify that :mod:`django.contrib.staticfiles` is correctly
  613. configured:
  614. * **staticfiles.E001**: The :setting:`STATICFILES_DIRS` setting is not a tuple
  615. or list.
  616. * **staticfiles.E002**: The :setting:`STATICFILES_DIRS` setting should not
  617. contain the :setting:`STATIC_ROOT` setting.