checks.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. ======================
  2. System check framework
  3. ======================
  4. .. versionadded:: 1.7
  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. Builtin tags
  11. ------------
  12. Django's system checks are organized using the following tags:
  13. * ``models``: Checks governing model, field and manager definitions.
  14. * ``signals``: Checks on signal declarations and handler registrations.
  15. * ``admin``: Checks of any admin site declarations.
  16. * ``compatibility``: Flagging potential problems with version upgrades.
  17. Some checks may be registered with multiple tags.
  18. Core system checks
  19. ------------------
  20. Models
  21. ~~~~~~
  22. * **models.E001**: ``<swappable>`` is not of the form ``app_label.app_name``.
  23. * **models.E002**: ``<SETTING>`` references ``<model>``, which has not been
  24. installed, or is abstract.
  25. * **models.E003**: The model has two many-to-many relations through the
  26. intermediate model ``<app_label>.<model>``.
  27. * **models.E004**: ``id`` can only be used as a field name if the field also
  28. sets ``primary_key=True``.
  29. * **models.E005**: The field ``<field name>`` from parent model ``<model>``
  30. clashes with the field ``<field name>`` from parent model ``<model>``.
  31. * **models.E006**: The field clashes with the field ``<field name>`` from model
  32. ``<model>``.
  33. * **models.E007**: Field ``<field name>`` has column name ``<column name>``
  34. that is used by another field.
  35. * **models.E008**: ``index_together`` must be a list or tuple.
  36. * **models.E009**: All ``index_together`` elements must be lists or tuples.
  37. * **models.E010**: ``unique_together`` must be a list or tuple.
  38. * **models.E011**: All ``unique_together`` elements must be lists or tuples.
  39. * **models.E012**: ``index_together/unique_together`` refers to the
  40. non-existent field ``<field name>``.
  41. * **models.E013**: ``index_together/unique_together`` refers to a
  42. ``ManyToManyField`` ``<field name>``, but ``ManyToManyField``\s are not
  43. supported for that option.
  44. * **models.E014**: ``ordering`` must be a tuple or list (even if you want to
  45. order by only one field).
  46. * **models.E015**: ``ordering`` refers to the non-existent field
  47. ``<field name>``.
  48. * **models.E016**: ``index_together/unique_together`` refers to field
  49. ``<field_name>`` which is not local to model ``<model>``.
  50. * **models.E017**: Proxy model ``<model>`` contains model fields.
  51. * **models.E018**: Autogenerated column name too long for field ``<field>``.
  52. Maximum length is ``<maximum length>`` for database ``<alias>``.
  53. * **models.E019**: Autogenerated column name too long for M2M field
  54. ``<M2M field>``. Maximum length is ``<maximum length>`` for database
  55. ``<alias>``.
  56. Fields
  57. ~~~~~~
  58. * **fields.E001**: Field names must not end with an underscore.
  59. * **fields.E002**: Field names must not contain ``"__"``.
  60. * **fields.E003**: ``pk`` is a reserved word that cannot be used as a field
  61. name.
  62. * **fields.E004**: ``choices`` must be an iterable (e.g., a list or tuple).
  63. * **fields.E005**: ``choices`` must be an iterable returning ``(actual value,
  64. human readable name)`` tuples.
  65. * **fields.E006**: ``db_index`` must be ``None``, ``True`` or ``False``.
  66. * **fields.E007**: Primary keys must not have ``null=True``.
  67. * **fields.E100**: ``AutoField``\s must set primary_key=True.
  68. * **fields.E110**: ``BooleanField``\s do not accept null values.
  69. * **fields.E120**: ``CharField``\s must define a ``max_length`` attribute.
  70. * **fields.E121**: ``max_length`` must be a positive integer.
  71. * **fields.E130**: ``DecimalField``\s must define a ``decimal_places`` attribute.
  72. * **fields.E131**: ``decimal_places`` must be a non-negative integer.
  73. * **fields.E132**: ``DecimalField``\s must define a ``max_digits`` attribute.
  74. * **fields.E133**: ``max_digits`` must be a non-negative integer.
  75. * **fields.E134**: ``max_digits`` must be greater or equal to ``decimal_places``.
  76. * **fields.E140**: ``FilePathField``\s must have either ``allow_files`` or
  77. ``allow_folders`` set to True.
  78. * **fields.E150**: ``GenericIPAddressField``\s cannot accept blank values if
  79. null values are not allowed, as blank values are stored as nulls.
  80. * **fields.E160**: The options ``auto_now``, ``auto_now_add``, and ``default``
  81. are mutually exclusive. Only one of these options may be present.
  82. * **fields.W161**: Fixed default value provided.
  83. File Fields
  84. ~~~~~~~~~~~
  85. * **fields.E200**: ``unique`` is not a valid argument for a ``FileField``.
  86. * **fields.E201**: ``primary_key`` is not a valid argument for a ``FileField``.
  87. * **fields.E210**: Cannot use ``ImageField`` because Pillow is not installed.
  88. Related Fields
  89. ~~~~~~~~~~~~~~
  90. * **fields.E300**: Field defines a relation with model ``<model>``, which is
  91. either not installed, or is abstract.
  92. * **fields.E301**: Field defines a relation with the model ``<model>`` which
  93. has been swapped out.
  94. * **fields.E302**: Accessor for field ``<field name>`` clashes with field
  95. ``<field name>``.
  96. * **fields.E303**: Reverse query name for field ``<field name>`` clashes with
  97. field ``<field name>``.
  98. * **fields.E304**: Field name ``<field name>`` clashes with accessor for
  99. ``<field name>``.
  100. * **fields.E305**: Field name ``<field name>`` clashes with reverse query name
  101. for ``<field name>``.
  102. * **fields.E310**: None of the fields ``<field1>``, ``<field2>``, ... on model
  103. ``<model>`` have a ``unique=True`` constraint.
  104. * **fields.E311**: ``<model>`` must set ``unique=True`` because it is
  105. referenced by a ``ForeignKey``.
  106. * **fields.E320**: Field specifies ``on_delete=SET_NULL``, but cannot be null.
  107. * **fields.E321**: The field specifies ``on_delete=SET_DEFAULT``, but has no
  108. default value.
  109. * **fields.E330**: ``ManyToManyField``\s cannot be unique.
  110. * **fields.E331**: Field specifies a many-to-many relation through model
  111. ``<model>``, which has not been installed.
  112. * **fields.E332**: Many-to-many fields with intermediate tables must not be
  113. symmetrical.
  114. * **fields.E333**: The model is used as an intermediate model by ``<model>``,
  115. but it has more than two foreign keys to ``<model>``, which is ambiguous.
  116. You must specify which two foreign keys Django should use via the
  117. ``through_fields`` keyword argument.
  118. * **fields.E334**: The model is used as an intermediate model by ``<model>``,
  119. but it has more than one foreign key from ``<model>``, which is ambiguous.
  120. You must specify which foreign key Django should use via the
  121. ``through_fields`` keyword argument.
  122. * **fields.E335**: The model is used as an intermediate model by ``<model>``,
  123. but it has more than one foreign key to ``<model>``, which is ambiguous.
  124. You must specify which foreign key Django should use via the
  125. ``through_fields`` keyword argument.
  126. * **fields.E336**: The model is used as an intermediary model by ``<model>``,
  127. but it does not have foreign key to ``<model>`` or ``<model>``.
  128. * **fields.E337**: Field specifies ``through_fields`` but does not provide the
  129. names of the two link fields that should be used for the relation through
  130. ``<model>``.
  131. * **fields.E338**: The intermediary model ``<through model>`` has no field
  132. ``<field name>``.
  133. * **fields.E339**: ``<model>.<field name>`` is not a foreign key to ``<model>``.
  134. * **fields.W340**: ``null`` has no effect on ``ManyToManyField``.
  135. * **fields.W341**: ``ManyToManyField`` does not support ``validators``.
  136. Signals
  137. ~~~~~~~
  138. * **signals.E001**: ``<handler>`` was connected to the ``<signal>`` signal with
  139. a lazy reference to the ``<model>`` sender, which has not been installed.
  140. Backwards Compatibility
  141. ~~~~~~~~~~~~~~~~~~~~~~~
  142. The following checks are performed to warn the user of any potential problems
  143. that might occur as a result of a version upgrade.
  144. * **1_6.W001**: Some project unit tests may not execute as expected.
  145. * **1_6.W002**: ``BooleanField`` does not have a default value.
  146. Admin
  147. -----
  148. Admin checks are all performed as part of the ``admin`` tag.
  149. The following checks are performed on any
  150. :class:`~django.contrib.admin.ModelAdmin` (or subclass) that is registered
  151. with the admin site:
  152. * **admin.E001**: The value of ``raw_id_fields`` must be a list or tuple.
  153. * **admin.E002**: The value of ``raw_id_fields[n]`` refers to ``<field name>``,
  154. which is not an attribute of ``<model>``.
  155. * **admin.E003**: The value of ``raw_id_fields[n]`` must be a ``ForeignKey`` or
  156. ``ManyToManyField``.
  157. * **admin.E004**: The value of ``fields`` must be a list or tuple.
  158. * **admin.E005**: Both ``fieldsets`` and ``fields`` are specified.
  159. * **admin.E006**: The value of ``fields`` contains duplicate field(s).
  160. * **admin.E007**: The value of ``fieldsets`` must be a list or tuple.
  161. * **admin.E008**: The value of ``fieldsets[n]`` must be a list or tuple.
  162. * **admin.E009**: The value of ``fieldsets[n]`` must be of length 2.
  163. * **admin.E010**: The value of ``fieldsets[n][1]`` must be a dictionary.
  164. * **admin.E011**: The value of ``fieldsets[n][1]`` must contain the key
  165. ``fields``.
  166. * **admin.E012**: There are duplicate field(s) in ``fieldsets[n][1]``.
  167. * **admin.E013**: ``fields[n]/fieldsets[n][m]`` cannot include the
  168. ``ManyToManyField`` ``<field name>``, because that field manually specifies a
  169. relationship model.
  170. * **admin.E014**: The value of ``exclude`` must be a list or tuple.
  171. * **admin.E015**: The value of ``exclude`` contains duplicate field(s).
  172. * **admin.E016**: The value of ``form`` must inherit from ``BaseModelForm``.
  173. * **admin.E017**: The value of ``filter_vertical`` must be a list or tuple.
  174. * **admin.E018**: The value of ``filter_horizontal`` must be a list or tuple.
  175. * **admin.E019**: The value of ``filter_vertical[n]/filter_vertical[n]`` refers
  176. to ``<field name>``, which is not an attribute of ``<model>``.
  177. * **admin.E020**: The value of ``filter_vertical[n]/filter_vertical[n]`` must
  178. be a ``ManyToManyField``.
  179. * **admin.E021**: The value of ``radio_fields`` must be a dictionary.
  180. * **admin.E022**: The value of ``radio_fields`` refers to ``<field name>``,
  181. which is not an attribute of ``<model>``.
  182. * **admin.E023**: The value of ``radio_fields`` refers to ``<field name>``,
  183. which is not a ``ForeignKey``, and does not have a ``choices`` definition.
  184. * **admin.E024**: The value of ``radio_fields[<field name>]`` must be either
  185. ``admin.HORIZONTAL`` or ``admin.VERTICAL``.
  186. * **admin.E025**: The value of ``view_on_site`` must be either a callable or a
  187. boolean value.
  188. * **admin.E026**: The value of ``prepopulated_fields`` must be a dictionary.
  189. * **admin.E027**: The value of ``prepopulated_fields`` refers to
  190. ``<field name>``, which is not an attribute of ``<model>``.
  191. * **admin.E028**: The value of ``prepopulated_fields`` refers to
  192. ``<field name>``, which must not be a ``DateTimeField``, ``ForeignKey`` or
  193. ``ManyToManyField``.
  194. * **admin.E029**: The value of ``prepopulated_fields[<field name>]`` must be a
  195. list or tuple.
  196. * **admin.E030**: The value of ``prepopulated_fields`` refers to
  197. ``<field name>``, which is not an attribute of ``<model>``.
  198. * **admin.E031**: The value of ``ordering`` must be a list or tuple.
  199. * **admin.E032**: The value of ``ordering`` has the random ordering marker
  200. ``?``, but contains other fields as well.
  201. * **admin.E033**: The value of ``ordering`` refers to ``<field name>``, which
  202. is not an attribute of ``<model>``.
  203. * **admin.E034**: The value of ``readonly_fields`` must be a list or tuple.
  204. * **admin.E035**: The value of ``readonly_fields[n]`` is not a callable, an
  205. attribute of ``<ModelAdmin class>``, or an attribute of ``<model>``.
  206. ModelAdmin
  207. ~~~~~~~~~~
  208. The following checks are performed on any
  209. :class:`~django.contrib.admin.ModelAdmin` that is registered
  210. with the admin site:
  211. * **admin.E101**: The value of ``save_as`` must be a boolean.
  212. * **admin.E102**: The value of ``save_on_top`` must be a boolean.
  213. * **admin.E103**: The value of ``inlines`` must be a list or tuple.
  214. * **admin.E104**: ``<InlineModelAdmin class>`` must inherit from
  215. ``BaseModelAdmin``.
  216. * **admin.E105**: ``<InlineModelAdmin class>`` must have a ``model`` attribute.
  217. * **admin.E106**: The value of ``<InlineModelAdmin class>.model`` must be a
  218. ``Model``.
  219. * **admin.E107**: The value of ``list_display`` must be a list or tuple.
  220. * **admin.E108**: The value of ``list_display[n]`` refers to ``<label>``,
  221. which is not a callable, an attribute of ``<ModelAdmin class>``, or an
  222. attribute or method on ``<model>``.
  223. * **admin.E109**: The value of ``list_display[n]`` must not be a
  224. ``ManyToManyField``.
  225. * **admin.E110**: The value of ``list_display_links`` must be a list, a tuple,
  226. or ``None``.
  227. * **admin.E111**: The value of ``list_display_links[n]`` refers to ``<label>``,
  228. which is not defined in ``list_display``.
  229. * **admin.E112**: The value of ``list_filter`` must be a list or tuple.
  230. * **admin.E113**: The value of ``list_filter[n]`` must inherit from
  231. ``ListFilter``.
  232. * **admin.E114**: The value of ``list_filter[n]`` must not inherit from
  233. ``FieldListFilter``.
  234. * **admin.E115**: The value of ``list_filter[n][1]`` must inherit from
  235. ``FieldListFilter``.
  236. * **admin.E116**: The value of ``list_filter[n]`` refers to ``<label>``,
  237. which does not refer to a Field.
  238. * **admin.E117**: The value of ``list_select_related`` must be a boolean,
  239. tuple or list.
  240. * **admin.E118**: The value of ``list_per_page`` must be an integer.
  241. * **admin.E119**: The value of ``list_max_show_all`` must be an integer.
  242. * **admin.E120**: The value of ``list_editable`` must be a list or tuple.
  243. * **admin.E121**: The value of ``list_editable[n]`` refers to ``<label>``,
  244. which is not an attribute of ``<model>``.
  245. * **admin.E122**: The value of ``list_editable[n]`` refers to ``<label>``,
  246. which is not contained in ``list_display``.
  247. * **admin.E123**: The value of ``list_editable[n]`` cannot be in both
  248. ``list_editable`` and ``list_display_links``.
  249. * **admin.E124**: The value of ``list_editable[n]`` refers to the first field
  250. in ``list_display`` (``<label>``), which cannot be used unless
  251. ``list_display_links`` is set.
  252. * **admin.E125**: The value of ``list_editable[n]`` refers to ``<field name>``,
  253. which is not editable through the admin.
  254. * **admin.E126**: The value of ``search_fields`` must be a list or tuple.
  255. * **admin.E127**: The value of ``date_hierarchy`` refers to ``<field name>``,
  256. which is not an attribute of ``<model>``.
  257. * **admin.E128**: The value of ``date_hierarchy`` must be a ``DateField`` or
  258. ``DateTimeField``.
  259. InlineModelAdmin
  260. ~~~~~~~~~~~~~~~~
  261. The following checks are performed on any
  262. :class:`~django.contrib.admin.InlineModelAdmin` that is registered as an
  263. inline on a :class:`~django.contrib.admin.ModelAdmin`.
  264. * **admin.E201**: Cannot exclude the field ``<field name>``, because it is the
  265. foreign key to the parent model ``<app_label>.<model>``.
  266. * **admin.E202**: ``<model>`` has no ``ForeignKey`` to ``<parent model>``./
  267. ``<model>`` has more than one ``ForeignKey`` to ``<parent model>``.
  268. * **admin.E203**: The value of ``extra`` must be an integer.
  269. * **admin.E204**: The value of ``max_num`` must be an integer.
  270. * **admin.E205**: The value of ``min_num`` must be an integer.
  271. * **admin.E206**: The value of ``formset`` must inherit from
  272. ``BaseModelFormSet``.
  273. GenericInlineModelAdmin
  274. ~~~~~~~~~~~~~~~~~~~~~~~
  275. The following checks are performed on any
  276. :class:`~django.contrib.contenttypes.admin.GenericInlineModelAdmin` that is
  277. registered as an inline on a :class:`~django.contrib.admin.ModelAdmin`.
  278. * **admin.E301**: ``'ct_field'`` references ``<label>``, which is not a field
  279. on ``<model>``.
  280. * **admin.E302**: ``'ct_fk_field'`` references ``<label>``, which is not a
  281. field on ``<model>``.
  282. * **admin.E303**: ``<model>`` has no ``GenericForeignKey``.
  283. * **admin.E304**: ``<model>`` has no ``GenericForeignKey`` using content type
  284. field ``<field name>`` and object ID field ``<field name>``.
  285. Auth
  286. ----
  287. * **auth.E001**: ``REQUIRED_FIELDS`` must be a list or tuple.
  288. * **auth.E002**: The field named as the ``USERNAME_FIELD`` for a custom user
  289. model must not be included in ``REQUIRED_FIELDS``.
  290. * **auth.E003**: ``<field>`` must be unique because it is named as the
  291. ``USERNAME_FIELD``.
  292. * **auth.W004**: ``<field>`` is named as the ``USERNAME_FIELD``, but it is not
  293. unique.
  294. Content Types
  295. -------------
  296. The following checks are performed when a model contains a
  297. :class:`~django.contrib.contenttypes.fields.GenericForeignKey` or
  298. :class:`~django.contrib.contenttypes.fields.GenericRelation`:
  299. * **contenttypes.E001**: The ``GenericForeignKey`` object ID references the
  300. non-existent field ``<field>``
  301. * **contenttypes.E002**: The ``GenericForeignKey`` content type references the
  302. non-existent field ``<field>``
  303. * **contenttypes.E003**: ``<field>`` is not a ``ForeignKey``.
  304. * **contenttypes.E004**: ``<field>`` is not a ``ForeignKey`` to
  305. ``contenttypes.ContentType``
  306. Sites
  307. -----
  308. The following checks are performed on any model using a
  309. :class:`~django.contrib.sites.managers.CurrentSiteManager`:
  310. * **sites.E001**: ``CurrentSiteManager`` could not find a field named
  311. ``<field name>``.
  312. * **sites.E002**: ``CurrentSiteManager`` cannot use ``<field>`` as it is not a
  313. ``ForeignKey`` or ``ManyToManyField``.
  314. Database
  315. --------
  316. MySQL
  317. ~~~~~
  318. If you're using MySQL, the following checks will be performed:
  319. * **mysql.E001**: MySQL does not allow unique ``CharField``\s to have a
  320. ``max_length`` > 255.