django-admin.1 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716
  1. .\" Man page generated from reStructuredText.
  2. .
  3. .
  4. .nr rst2man-indent-level 0
  5. .
  6. .de1 rstReportMargin
  7. \\$1 \\n[an-margin]
  8. level \\n[rst2man-indent-level]
  9. level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
  10. -
  11. \\n[rst2man-indent0]
  12. \\n[rst2man-indent1]
  13. \\n[rst2man-indent2]
  14. ..
  15. .de1 INDENT
  16. .\" .rstReportMargin pre:
  17. . RS \\$1
  18. . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
  19. . nr rst2man-indent-level +1
  20. .\" .rstReportMargin post:
  21. ..
  22. .de UNINDENT
  23. . RE
  24. .\" indent \\n[an-margin]
  25. .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
  26. .nr rst2man-indent-level -1
  27. .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
  28. .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
  29. ..
  30. .TH "DJANGO-ADMIN" "1" "May 22, 2024" "5.1" "Django"
  31. .SH NAME
  32. django-admin \- Utility script for the Django web framework
  33. .sp
  34. \fBdjango\-admin\fP is Django\(aqs command\-line utility for administrative tasks.
  35. This document outlines all it can do.
  36. .sp
  37. In addition, \fBmanage.py\fP is automatically created in each Django project. It
  38. does the same thing as \fBdjango\-admin\fP but also sets the
  39. \X'tty: link #envvar-DJANGO_SETTINGS_MODULE'\fI\%DJANGO_SETTINGS_MODULE\fP\X'tty: link' environment variable so that it points to your
  40. project\(aqs \fBsettings.py\fP file.
  41. .sp
  42. The \fBdjango\-admin\fP script should be on your system path if you installed
  43. Django via \fBpip\fP\&. If it\(aqs not in your path, ensure you have your virtual
  44. environment activated.
  45. .sp
  46. Generally, when working on a single Django project, it\(aqs easier to use
  47. \fBmanage.py\fP than \fBdjango\-admin\fP\&. If you need to switch between multiple
  48. Django settings files, use \fBdjango\-admin\fP with
  49. \X'tty: link #envvar-DJANGO_SETTINGS_MODULE'\fI\%DJANGO_SETTINGS_MODULE\fP\X'tty: link' or the \fI\%\-\-settings\fP command line
  50. option.
  51. .sp
  52. The command\-line examples throughout this document use \fBdjango\-admin\fP to
  53. be consistent, but any example can use \fBmanage.py\fP or \fBpython \-m django\fP
  54. just as well.
  55. .SH USAGE
  56. .INDENT 0.0
  57. .INDENT 3.5
  58. .sp
  59. .EX
  60. $ django\-admin <command> [options]
  61. $ manage.py <command> [options]
  62. $ python \-m django <command> [options]
  63. .EE
  64. .UNINDENT
  65. .UNINDENT
  66. .sp
  67. \fBcommand\fP should be one of the commands listed in this document.
  68. \fBoptions\fP, which is optional, should be zero or more of the options available
  69. for the given command.
  70. .SS Getting runtime help
  71. .INDENT 0.0
  72. .TP
  73. .B django\-admin help
  74. .UNINDENT
  75. .sp
  76. Run \fBdjango\-admin help\fP to display usage information and a list of the
  77. commands provided by each application.
  78. .sp
  79. Run \fBdjango\-admin help \-\-commands\fP to display a list of all available
  80. commands.
  81. .sp
  82. Run \fBdjango\-admin help <command>\fP to display a description of the given
  83. command and a list of its available options.
  84. .SS App names
  85. .sp
  86. Many commands take a list of \(dqapp names.\(dq An \(dqapp name\(dq is the basename of
  87. the package containing your models. For example, if your \X'tty: link #std-setting-INSTALLED_APPS'\fI\%INSTALLED_APPS\fP\X'tty: link'
  88. contains the string \fB\(aqmysite.blog\(aq\fP, the app name is \fBblog\fP\&.
  89. .SS Determining the version
  90. .INDENT 0.0
  91. .TP
  92. .B django\-admin version
  93. .UNINDENT
  94. .sp
  95. Run \fBdjango\-admin version\fP to display the current Django version.
  96. .sp
  97. The output follows the schema described in \X'tty: link https://peps.python.org/pep-0440/'\fI\%PEP 440\fP\X'tty: link':
  98. .INDENT 0.0
  99. .INDENT 3.5
  100. .sp
  101. .EX
  102. 1.4.dev17026
  103. 1.4a1
  104. 1.4
  105. .EE
  106. .UNINDENT
  107. .UNINDENT
  108. .SS Displaying debug output
  109. .sp
  110. Use \fI\%\-\-verbosity\fP, where it is supported, to specify the amount of
  111. notification and debug information that \fBdjango\-admin\fP prints to the console.
  112. .SH AVAILABLE COMMANDS
  113. .SS \fBcheck\fP
  114. .INDENT 0.0
  115. .TP
  116. .B django\-admin check [app_label [app_label ...]]
  117. .UNINDENT
  118. .sp
  119. Uses the \fI\%system check framework\fP to inspect the entire
  120. Django project for common problems.
  121. .sp
  122. By default, all apps will be checked. You can check a subset of apps by
  123. providing a list of app labels as arguments:
  124. .INDENT 0.0
  125. .INDENT 3.5
  126. .sp
  127. .EX
  128. django\-admin check auth admin myapp
  129. .EE
  130. .UNINDENT
  131. .UNINDENT
  132. .INDENT 0.0
  133. .TP
  134. .B \-\-tag TAGS, \-t TAGS
  135. .UNINDENT
  136. .sp
  137. The system check framework performs many different types of checks that are
  138. \X'tty: link #system-check-builtin-tags'\fI\%categorized with tags\fP\X'tty: link'\&. You can use these
  139. tags to restrict the checks performed to just those in a particular category.
  140. For example, to perform only models and compatibility checks, run:
  141. .INDENT 0.0
  142. .INDENT 3.5
  143. .sp
  144. .EX
  145. django\-admin check \-\-tag models \-\-tag compatibility
  146. .EE
  147. .UNINDENT
  148. .UNINDENT
  149. .INDENT 0.0
  150. .TP
  151. .B \-\-database DATABASE
  152. .UNINDENT
  153. .sp
  154. Specifies the database to run checks requiring database access:
  155. .INDENT 0.0
  156. .INDENT 3.5
  157. .sp
  158. .EX
  159. django\-admin check \-\-database default \-\-database other
  160. .EE
  161. .UNINDENT
  162. .UNINDENT
  163. .sp
  164. By default, these checks will not be run.
  165. .INDENT 0.0
  166. .TP
  167. .B \-\-list\-tags
  168. .UNINDENT
  169. .sp
  170. Lists all available tags.
  171. .INDENT 0.0
  172. .TP
  173. .B \-\-deploy
  174. .UNINDENT
  175. .sp
  176. Activates some additional checks that are only relevant in a deployment setting.
  177. .sp
  178. You can use this option in your local development environment, but since your
  179. local development settings module may not have many of your production settings,
  180. you will probably want to point the \fBcheck\fP command at a different settings
  181. module, either by setting the \X'tty: link #envvar-DJANGO_SETTINGS_MODULE'\fI\%DJANGO_SETTINGS_MODULE\fP\X'tty: link' environment
  182. variable, or by passing the \fB\-\-settings\fP option:
  183. .INDENT 0.0
  184. .INDENT 3.5
  185. .sp
  186. .EX
  187. django\-admin check \-\-deploy \-\-settings=production_settings
  188. .EE
  189. .UNINDENT
  190. .UNINDENT
  191. .sp
  192. Or you could run it directly on a production or staging deployment to verify
  193. that the correct settings are in use (omitting \fB\-\-settings\fP). You could even
  194. make it part of your integration test suite.
  195. .INDENT 0.0
  196. .TP
  197. .B \-\-fail\-level {CRITICAL,ERROR,WARNING,INFO,DEBUG}
  198. .UNINDENT
  199. .sp
  200. Specifies the message level that will cause the command to exit with a non\-zero
  201. status. Default is \fBERROR\fP\&.
  202. .SS \fBcompilemessages\fP
  203. .INDENT 0.0
  204. .TP
  205. .B django\-admin compilemessages
  206. .UNINDENT
  207. .sp
  208. Compiles \fB\&.po\fP files created by \fI\%makemessages\fP to \fB\&.mo\fP files for
  209. use with the built\-in gettext support. See \fI\%Internationalization and localization\fP\&.
  210. .INDENT 0.0
  211. .TP
  212. .B \-\-locale LOCALE, \-l LOCALE
  213. .UNINDENT
  214. .sp
  215. Specifies the locale(s) to process. If not provided, all locales are processed.
  216. .INDENT 0.0
  217. .TP
  218. .B \-\-exclude EXCLUDE, \-x EXCLUDE
  219. .UNINDENT
  220. .sp
  221. Specifies the locale(s) to exclude from processing. If not provided, no locales
  222. are excluded.
  223. .INDENT 0.0
  224. .TP
  225. .B \-\-use\-fuzzy, \-f
  226. .UNINDENT
  227. .sp
  228. Includes \X'tty: link https://www.gnu.org/software/gettext/manual/html_node/Fuzzy-Entries.html'\fI\%fuzzy translations\fP\X'tty: link' into compiled files.
  229. .sp
  230. Example usage:
  231. .INDENT 0.0
  232. .INDENT 3.5
  233. .sp
  234. .EX
  235. django\-admin compilemessages \-\-locale=pt_BR
  236. django\-admin compilemessages \-\-locale=pt_BR \-\-locale=fr \-f
  237. django\-admin compilemessages \-l pt_BR
  238. django\-admin compilemessages \-l pt_BR \-l fr \-\-use\-fuzzy
  239. django\-admin compilemessages \-\-exclude=pt_BR
  240. django\-admin compilemessages \-\-exclude=pt_BR \-\-exclude=fr
  241. django\-admin compilemessages \-x pt_BR
  242. django\-admin compilemessages \-x pt_BR \-x fr
  243. .EE
  244. .UNINDENT
  245. .UNINDENT
  246. .INDENT 0.0
  247. .TP
  248. .B \-\-ignore PATTERN, \-i PATTERN
  249. .UNINDENT
  250. .sp
  251. Ignores directories matching the given \X'tty: link https://docs.python.org/3/library/glob.html#module-glob'\fI\%glob\fP\X'tty: link'\-style pattern. Use
  252. multiple times to ignore more.
  253. .sp
  254. Example usage:
  255. .INDENT 0.0
  256. .INDENT 3.5
  257. .sp
  258. .EX
  259. django\-admin compilemessages \-\-ignore=cache \-\-ignore=outdated/*/locale
  260. .EE
  261. .UNINDENT
  262. .UNINDENT
  263. .SS \fBcreatecachetable\fP
  264. .INDENT 0.0
  265. .TP
  266. .B django\-admin createcachetable
  267. .UNINDENT
  268. .sp
  269. Creates the cache tables for use with the database cache backend using the
  270. information from your settings file. See \fI\%Django\(aqs cache framework\fP for more
  271. information.
  272. .INDENT 0.0
  273. .TP
  274. .B \-\-database DATABASE
  275. .UNINDENT
  276. .sp
  277. Specifies the database in which the cache table(s) will be created. Defaults to
  278. \fBdefault\fP\&.
  279. .INDENT 0.0
  280. .TP
  281. .B \-\-dry\-run
  282. .UNINDENT
  283. .sp
  284. Prints the SQL that would be run without actually running it, so you can
  285. customize it or use the migrations framework.
  286. .SS \fBdbshell\fP
  287. .INDENT 0.0
  288. .TP
  289. .B django\-admin dbshell
  290. .UNINDENT
  291. .sp
  292. Runs the command\-line client for the database engine specified in your
  293. \X'tty: link #std-setting-DATABASE-ENGINE'\fI\%ENGINE\fP\X'tty: link' setting, with the connection parameters
  294. specified in your \X'tty: link #std-setting-USER'\fI\%USER\fP\X'tty: link', \X'tty: link #std-setting-PASSWORD'\fI\%PASSWORD\fP\X'tty: link', etc., settings.
  295. .INDENT 0.0
  296. .IP \(bu 2
  297. For PostgreSQL, this runs the \fBpsql\fP command\-line client.
  298. .IP \(bu 2
  299. For MySQL, this runs the \fBmysql\fP command\-line client.
  300. .IP \(bu 2
  301. For SQLite, this runs the \fBsqlite3\fP command\-line client.
  302. .IP \(bu 2
  303. For Oracle, this runs the \fBsqlplus\fP command\-line client.
  304. .UNINDENT
  305. .sp
  306. This command assumes the programs are on your \fBPATH\fP so that a call to
  307. the program name (\fBpsql\fP, \fBmysql\fP, \fBsqlite3\fP, \fBsqlplus\fP) will find the
  308. program in the right place. There\(aqs no way to specify the location of the
  309. program manually.
  310. .INDENT 0.0
  311. .TP
  312. .B \-\-database DATABASE
  313. .UNINDENT
  314. .sp
  315. Specifies the database onto which to open a shell. Defaults to \fBdefault\fP\&.
  316. .INDENT 0.0
  317. .TP
  318. .B \-\- ARGUMENTS
  319. .UNINDENT
  320. .sp
  321. Any arguments following a \fB\-\-\fP divider will be passed on to the underlying
  322. command\-line client. For example, with PostgreSQL you can use the \fBpsql\fP
  323. command\(aqs \fB\-c\fP flag to execute a raw SQL query directly:
  324. .INDENT 0.0
  325. .INDENT 3.5
  326. .sp
  327. .EX
  328. $ django\-admin dbshell \-\- \-c \(aqselect current_user\(aq
  329. current_user
  330. \-\-\-\-\-\-\-\-\-\-\-\-\-\-
  331. postgres
  332. (1 row)
  333. .EE
  334. .UNINDENT
  335. .UNINDENT
  336. .sp
  337. On MySQL/MariaDB, you can do this with the \fBmysql\fP command\(aqs \fB\-e\fP flag:
  338. .INDENT 0.0
  339. .INDENT 3.5
  340. .sp
  341. .EX
  342. $ django\-admin dbshell \-\- \-e \(dqselect user()\(dq
  343. +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
  344. | user() |
  345. +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
  346. | djangonaut@localhost |
  347. +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
  348. .EE
  349. .UNINDENT
  350. .UNINDENT
  351. .sp
  352. \fBNOTE:\fP
  353. .INDENT 0.0
  354. .INDENT 3.5
  355. Be aware that not all options set in the \X'tty: link #std-setting-OPTIONS'\fI\%OPTIONS\fP\X'tty: link' part of your
  356. database configuration in \X'tty: link #std-setting-DATABASES'\fI\%DATABASES\fP\X'tty: link' are passed to the
  357. command\-line client, e.g. \fB\(aqisolation_level\(aq\fP\&.
  358. .UNINDENT
  359. .UNINDENT
  360. .SS \fBdiffsettings\fP
  361. .INDENT 0.0
  362. .TP
  363. .B django\-admin diffsettings
  364. .UNINDENT
  365. .sp
  366. Displays differences between the current settings file and Django\(aqs default
  367. settings (or another settings file specified by \fI\%\-\-default\fP).
  368. .sp
  369. Settings that don\(aqt appear in the defaults are followed by \fB\(dq###\(dq\fP\&. For
  370. example, the default settings don\(aqt define \X'tty: link #std-setting-ROOT_URLCONF'\fI\%ROOT_URLCONF\fP\X'tty: link', so
  371. \X'tty: link #std-setting-ROOT_URLCONF'\fI\%ROOT_URLCONF\fP\X'tty: link' is followed by \fB\(dq###\(dq\fP in the output of
  372. \fBdiffsettings\fP\&.
  373. .INDENT 0.0
  374. .TP
  375. .B \-\-all
  376. .UNINDENT
  377. .sp
  378. Displays all settings, even if they have Django\(aqs default value. Such settings
  379. are prefixed by \fB\(dq###\(dq\fP\&.
  380. .INDENT 0.0
  381. .TP
  382. .B \-\-default MODULE
  383. .UNINDENT
  384. .sp
  385. The settings module to compare the current settings against. Leave empty to
  386. compare against Django\(aqs default settings.
  387. .INDENT 0.0
  388. .TP
  389. .B \-\-output {hash,unified}
  390. .UNINDENT
  391. .sp
  392. Specifies the output format. Available values are \fBhash\fP and \fBunified\fP\&.
  393. \fBhash\fP is the default mode that displays the output that\(aqs described above.
  394. \fBunified\fP displays the output similar to \fBdiff \-u\fP\&. Default settings are
  395. prefixed with a minus sign, followed by the changed setting prefixed with a
  396. plus sign.
  397. .SS \fBdumpdata\fP
  398. .INDENT 0.0
  399. .TP
  400. .B django\-admin dumpdata [app_label[.ModelName] [app_label[.ModelName] ...]]
  401. .UNINDENT
  402. .sp
  403. Outputs to standard output all data in the database associated with the named
  404. application(s).
  405. .sp
  406. If no application name is provided, all installed applications will be dumped.
  407. .sp
  408. The output of \fBdumpdata\fP can be used as input for \fI\%loaddata\fP\&.
  409. .sp
  410. When result of \fBdumpdata\fP is saved as a file, it can serve as a
  411. \X'tty: link #fixtures-explanation'\fI\%fixture\fP\X'tty: link' for
  412. \X'tty: link #topics-testing-fixtures'\fI\%tests\fP\X'tty: link' or as an
  413. \X'tty: link #initial-data-via-fixtures'\fI\%initial data\fP\X'tty: link'\&.
  414. .sp
  415. Note that \fBdumpdata\fP uses the default manager on the model for selecting the
  416. records to dump. If you\(aqre using a \X'tty: link #custom-managers'\fI\%custom manager\fP\X'tty: link' as
  417. the default manager and it filters some of the available records, not all of the
  418. objects will be dumped.
  419. .INDENT 0.0
  420. .TP
  421. .B \-\-all, \-a
  422. .UNINDENT
  423. .sp
  424. Uses Django\(aqs base manager, dumping records which might otherwise be filtered
  425. or modified by a custom manager.
  426. .INDENT 0.0
  427. .TP
  428. .B \-\-format FORMAT
  429. .UNINDENT
  430. .sp
  431. Specifies the serialization format of the output. Defaults to JSON. Supported
  432. formats are listed in \X'tty: link #serialization-formats'\fI\%Serialization formats\fP\X'tty: link'\&.
  433. .INDENT 0.0
  434. .TP
  435. .B \-\-indent INDENT
  436. .UNINDENT
  437. .sp
  438. Specifies the number of indentation spaces to use in the output. Defaults to
  439. \fBNone\fP which displays all data on single line.
  440. .INDENT 0.0
  441. .TP
  442. .B \-\-exclude EXCLUDE, \-e EXCLUDE
  443. .UNINDENT
  444. .sp
  445. Prevents specific applications or models (specified in the form of
  446. \fBapp_label.ModelName\fP) from being dumped. If you specify a model name, then
  447. only that model will be excluded, rather than the entire application. You can
  448. also mix application names and model names.
  449. .sp
  450. If you want to exclude multiple applications, pass \fB\-\-exclude\fP more than
  451. once:
  452. .INDENT 0.0
  453. .INDENT 3.5
  454. .sp
  455. .EX
  456. django\-admin dumpdata \-\-exclude=auth \-\-exclude=contenttypes
  457. .EE
  458. .UNINDENT
  459. .UNINDENT
  460. .INDENT 0.0
  461. .TP
  462. .B \-\-database DATABASE
  463. .UNINDENT
  464. .sp
  465. Specifies the database from which data will be dumped. Defaults to \fBdefault\fP\&.
  466. .INDENT 0.0
  467. .TP
  468. .B \-\-natural\-foreign
  469. .UNINDENT
  470. .sp
  471. Uses the \fBnatural_key()\fP model method to serialize any foreign key and
  472. many\-to\-many relationship to objects of the type that defines the method. If
  473. you\(aqre dumping \fBcontrib.auth\fP \fBPermission\fP objects or
  474. \fBcontrib.contenttypes\fP \fBContentType\fP objects, you should probably use this
  475. flag. See the \X'tty: link #topics-serialization-natural-keys'\fI\%natural keys\fP\X'tty: link'
  476. documentation for more details on this and the next option.
  477. .INDENT 0.0
  478. .TP
  479. .B \-\-natural\-primary
  480. .UNINDENT
  481. .sp
  482. Omits the primary key in the serialized data of this object since it can be
  483. calculated during deserialization.
  484. .INDENT 0.0
  485. .TP
  486. .B \-\-pks PRIMARY_KEYS
  487. .UNINDENT
  488. .sp
  489. Outputs only the objects specified by a comma separated list of primary keys.
  490. This is only available when dumping one model. By default, all the records of
  491. the model are output.
  492. .INDENT 0.0
  493. .TP
  494. .B \-\-output OUTPUT, \-o OUTPUT
  495. .UNINDENT
  496. .sp
  497. Specifies a file to write the serialized data to. By default, the data goes to
  498. standard output.
  499. .sp
  500. When this option is set and \fB\-\-verbosity\fP is greater than 0 (the default), a
  501. progress bar is shown in the terminal.
  502. .SS Fixtures compression
  503. .sp
  504. The output file can be compressed with one of the \fBbz2\fP, \fBgz\fP, \fBlzma\fP, or
  505. \fBxz\fP formats by ending the filename with the corresponding extension.
  506. For example, to output the data as a compressed JSON file:
  507. .INDENT 0.0
  508. .INDENT 3.5
  509. .sp
  510. .EX
  511. django\-admin dumpdata \-o mydata.json.gz
  512. .EE
  513. .UNINDENT
  514. .UNINDENT
  515. .SS \fBflush\fP
  516. .INDENT 0.0
  517. .TP
  518. .B django\-admin flush
  519. .UNINDENT
  520. .sp
  521. Removes all data from the database and re\-executes any post\-synchronization
  522. handlers. The table of which migrations have been applied is not cleared.
  523. .sp
  524. If you would rather start from an empty database and rerun all migrations, you
  525. should drop and recreate the database and then run \fI\%migrate\fP instead.
  526. .INDENT 0.0
  527. .TP
  528. .B \-\-noinput, \-\-no\-input
  529. .UNINDENT
  530. .sp
  531. Suppresses all user prompts.
  532. .INDENT 0.0
  533. .TP
  534. .B \-\-database DATABASE
  535. .UNINDENT
  536. .sp
  537. Specifies the database to flush. Defaults to \fBdefault\fP\&.
  538. .SS \fBinspectdb\fP
  539. .INDENT 0.0
  540. .TP
  541. .B django\-admin inspectdb [table [table ...]]
  542. .UNINDENT
  543. .sp
  544. Introspects the database tables in the database pointed\-to by the
  545. \X'tty: link #std-setting-NAME'\fI\%NAME\fP\X'tty: link' setting and outputs a Django model module (a \fBmodels.py\fP
  546. file) to standard output.
  547. .sp
  548. You may choose what tables or views to inspect by passing their names as
  549. arguments. If no arguments are provided, models are created for views only if
  550. the \fI\%\-\-include\-views\fP option is used. Models for partition tables are
  551. created on PostgreSQL if the \fI\%\-\-include\-partitions\fP option is used.
  552. .sp
  553. Use this if you have a legacy database with which you\(aqd like to use Django.
  554. The script will inspect the database and create a model for each table within
  555. it.
  556. .sp
  557. As you might expect, the created models will have an attribute for every field
  558. in the table. Note that \fBinspectdb\fP has a few special cases in its field\-name
  559. output:
  560. .INDENT 0.0
  561. .IP \(bu 2
  562. If \fBinspectdb\fP cannot map a column\(aqs type to a model field type, it\(aqll
  563. use \fBTextField\fP and will insert the Python comment
  564. \fB\(aqThis field type is a guess.\(aq\fP next to the field in the generated
  565. model. The recognized fields may depend on apps listed in
  566. \X'tty: link #std-setting-INSTALLED_APPS'\fI\%INSTALLED_APPS\fP\X'tty: link'\&. For example, \X'tty: link #module-django.contrib.postgres'\fI\%django.contrib.postgres\fP\X'tty: link' adds
  567. recognition for several PostgreSQL\-specific field types.
  568. .IP \(bu 2
  569. If the database column name is a Python reserved word (such as
  570. \fB\(aqpass\(aq\fP, \fB\(aqclass\(aq\fP or \fB\(aqfor\(aq\fP), \fBinspectdb\fP will append
  571. \fB\(aq_field\(aq\fP to the attribute name. For example, if a table has a column
  572. \fB\(aqfor\(aq\fP, the generated model will have a field \fB\(aqfor_field\(aq\fP, with
  573. the \fBdb_column\fP attribute set to \fB\(aqfor\(aq\fP\&. \fBinspectdb\fP will insert
  574. the Python comment
  575. \fB\(aqField renamed because it was a Python reserved word.\(aq\fP next to the
  576. field.
  577. .UNINDENT
  578. .sp
  579. This feature is meant as a shortcut, not as definitive model generation. After
  580. you run it, you\(aqll want to look over the generated models yourself to make
  581. customizations. In particular, you\(aqll need to rearrange models\(aq order, so that
  582. models that refer to other models are ordered properly.
  583. .sp
  584. Django doesn\(aqt create database defaults when a
  585. \X'tty: link #django.db.models.Field.default'\fI\%default\fP\X'tty: link' is specified on a model field.
  586. Similarly, database defaults aren\(aqt translated to model field defaults or
  587. detected in any fashion by \fBinspectdb\fP\&.
  588. .sp
  589. By default, \fBinspectdb\fP creates unmanaged models. That is, \fBmanaged = False\fP
  590. in the model\(aqs \fBMeta\fP class tells Django not to manage each table\(aqs creation,
  591. modification, and deletion. If you do want to allow Django to manage the
  592. table\(aqs lifecycle, you\(aqll need to change the
  593. \X'tty: link #django.db.models.Options.managed'\fI\%managed\fP\X'tty: link' option to \fBTrue\fP (or remove
  594. it because \fBTrue\fP is its default value).
  595. .SS Database\-specific notes
  596. .SS Oracle
  597. .INDENT 0.0
  598. .IP \(bu 2
  599. Models are created for materialized views if \fI\%\-\-include\-views\fP is
  600. used.
  601. .UNINDENT
  602. .SS PostgreSQL
  603. .INDENT 0.0
  604. .IP \(bu 2
  605. Models are created for foreign tables.
  606. .IP \(bu 2
  607. Models are created for materialized views if
  608. \fI\%\-\-include\-views\fP is used.
  609. .IP \(bu 2
  610. Models are created for partition tables if
  611. \fI\%\-\-include\-partitions\fP is used.
  612. .UNINDENT
  613. .INDENT 0.0
  614. .TP
  615. .B \-\-database DATABASE
  616. .UNINDENT
  617. .sp
  618. Specifies the database to introspect. Defaults to \fBdefault\fP\&.
  619. .INDENT 0.0
  620. .TP
  621. .B \-\-include\-partitions
  622. .UNINDENT
  623. .sp
  624. If this option is provided, models are also created for partitions.
  625. .sp
  626. Only support for PostgreSQL is implemented.
  627. .INDENT 0.0
  628. .TP
  629. .B \-\-include\-views
  630. .UNINDENT
  631. .sp
  632. If this option is provided, models are also created for database views.
  633. .SS \fBloaddata\fP
  634. .INDENT 0.0
  635. .TP
  636. .B django\-admin loaddata fixture [fixture ...]
  637. .UNINDENT
  638. .sp
  639. Searches for and loads the contents of the named
  640. \X'tty: link #fixtures-explanation'\fI\%fixture\fP\X'tty: link' into the database.
  641. .INDENT 0.0
  642. .TP
  643. .B \-\-database DATABASE
  644. .UNINDENT
  645. .sp
  646. Specifies the database into which the data will be loaded. Defaults to
  647. \fBdefault\fP\&.
  648. .INDENT 0.0
  649. .TP
  650. .B \-\-ignorenonexistent, \-i
  651. .UNINDENT
  652. .sp
  653. Ignores fields and models that may have been removed since the fixture was
  654. originally generated.
  655. .INDENT 0.0
  656. .TP
  657. .B \-\-app APP_LABEL
  658. .UNINDENT
  659. .sp
  660. Specifies a single app to look for fixtures in rather than looking in all apps.
  661. .INDENT 0.0
  662. .TP
  663. .B \-\-format FORMAT
  664. .UNINDENT
  665. .sp
  666. Specifies the \X'tty: link #serialization-formats'\fI\%serialization format\fP\X'tty: link' (e.g.,
  667. \fBjson\fP or \fBxml\fP) for fixtures \fI\%read from stdin\fP\&.
  668. .INDENT 0.0
  669. .TP
  670. .B \-\-exclude EXCLUDE, \-e EXCLUDE
  671. .UNINDENT
  672. .sp
  673. Excludes loading the fixtures from the given applications and/or models (in the
  674. form of \fBapp_label\fP or \fBapp_label.ModelName\fP). Use the option multiple
  675. times to exclude more than one app or model.
  676. .SS Loading fixtures from \fBstdin\fP
  677. .sp
  678. You can use a dash as the fixture name to load input from \fBsys.stdin\fP\&. For
  679. example:
  680. .INDENT 0.0
  681. .INDENT 3.5
  682. .sp
  683. .EX
  684. django\-admin loaddata \-\-format=json \-
  685. .EE
  686. .UNINDENT
  687. .UNINDENT
  688. .sp
  689. When reading from \fBstdin\fP, the \fI\%\-\-format\fP option
  690. is required to specify the \X'tty: link #serialization-formats'\fI\%serialization format\fP\X'tty: link'
  691. of the input (e.g., \fBjson\fP or \fBxml\fP).
  692. .sp
  693. Loading from \fBstdin\fP is useful with standard input and output redirections.
  694. For example:
  695. .INDENT 0.0
  696. .INDENT 3.5
  697. .sp
  698. .EX
  699. django\-admin dumpdata \-\-format=json \-\-database=test app_label.ModelName | django\-admin loaddata \-\-format=json \-\-database=prod \-
  700. .EE
  701. .UNINDENT
  702. .UNINDENT
  703. .sp
  704. The \fI\%dumpdata\fP command can be used to generate input for \fBloaddata\fP\&.
  705. .sp
  706. \fBSEE ALSO:\fP
  707. .INDENT 0.0
  708. .INDENT 3.5
  709. For more detail about fixtures see the \X'tty: link #fixtures-explanation'\fI\%Fixtures\fP\X'tty: link' topic.
  710. .UNINDENT
  711. .UNINDENT
  712. .SS \fBmakemessages\fP
  713. .INDENT 0.0
  714. .TP
  715. .B django\-admin makemessages
  716. .UNINDENT
  717. .sp
  718. Runs over the entire source tree of the current directory and pulls out all
  719. strings marked for translation. It creates (or updates) a message file in the
  720. conf/locale (in the Django tree) or locale (for project and application)
  721. directory. After making changes to the messages files you need to compile them
  722. with \fI\%compilemessages\fP for use with the builtin gettext support. See
  723. the \X'tty: link #how-to-create-language-files'\fI\%i18n documentation\fP\X'tty: link' for details.
  724. .sp
  725. This command doesn\(aqt require configured settings. However, when settings aren\(aqt
  726. configured, the command can\(aqt ignore the \X'tty: link #std-setting-MEDIA_ROOT'\fI\%MEDIA_ROOT\fP\X'tty: link' and
  727. \X'tty: link #std-setting-STATIC_ROOT'\fI\%STATIC_ROOT\fP\X'tty: link' directories or include \X'tty: link #std-setting-LOCALE_PATHS'\fI\%LOCALE_PATHS\fP\X'tty: link'\&.
  728. .INDENT 0.0
  729. .TP
  730. .B \-\-all, \-a
  731. .UNINDENT
  732. .sp
  733. Updates the message files for all available languages.
  734. .INDENT 0.0
  735. .TP
  736. .B \-\-extension EXTENSIONS, \-e EXTENSIONS
  737. .UNINDENT
  738. .sp
  739. Specifies a list of file extensions to examine (default: \fBhtml\fP, \fBtxt\fP,
  740. \fBpy\fP or \fBjs\fP if \fI\%\-\-domain\fP is \fBdjangojs\fP).
  741. .sp
  742. Example usage:
  743. .INDENT 0.0
  744. .INDENT 3.5
  745. .sp
  746. .EX
  747. django\-admin makemessages \-\-locale=de \-\-extension xhtml
  748. .EE
  749. .UNINDENT
  750. .UNINDENT
  751. .sp
  752. Separate multiple extensions with commas or use \fB\-e\fP or \fB\-\-extension\fP
  753. multiple times:
  754. .INDENT 0.0
  755. .INDENT 3.5
  756. .sp
  757. .EX
  758. django\-admin makemessages \-\-locale=de \-\-extension=html,txt \-\-extension xml
  759. .EE
  760. .UNINDENT
  761. .UNINDENT
  762. .INDENT 0.0
  763. .TP
  764. .B \-\-locale LOCALE, \-l LOCALE
  765. .UNINDENT
  766. .sp
  767. Specifies the locale(s) to process.
  768. .INDENT 0.0
  769. .TP
  770. .B \-\-exclude EXCLUDE, \-x EXCLUDE
  771. .UNINDENT
  772. .sp
  773. Specifies the locale(s) to exclude from processing. If not provided, no locales
  774. are excluded.
  775. .sp
  776. Example usage:
  777. .INDENT 0.0
  778. .INDENT 3.5
  779. .sp
  780. .EX
  781. django\-admin makemessages \-\-locale=pt_BR
  782. django\-admin makemessages \-\-locale=pt_BR \-\-locale=fr
  783. django\-admin makemessages \-l pt_BR
  784. django\-admin makemessages \-l pt_BR \-l fr
  785. django\-admin makemessages \-\-exclude=pt_BR
  786. django\-admin makemessages \-\-exclude=pt_BR \-\-exclude=fr
  787. django\-admin makemessages \-x pt_BR
  788. django\-admin makemessages \-x pt_BR \-x fr
  789. .EE
  790. .UNINDENT
  791. .UNINDENT
  792. .INDENT 0.0
  793. .TP
  794. .B \-\-domain DOMAIN, \-d DOMAIN
  795. .UNINDENT
  796. .sp
  797. Specifies the domain of the messages files. Supported options are:
  798. .INDENT 0.0
  799. .IP \(bu 2
  800. \fBdjango\fP for all \fB*.py\fP, \fB*.html\fP and \fB*.txt\fP files (default)
  801. .IP \(bu 2
  802. \fBdjangojs\fP for \fB*.js\fP files
  803. .UNINDENT
  804. .INDENT 0.0
  805. .TP
  806. .B \-\-symlinks, \-s
  807. .UNINDENT
  808. .sp
  809. Follows symlinks to directories when looking for new translation strings.
  810. .sp
  811. Example usage:
  812. .INDENT 0.0
  813. .INDENT 3.5
  814. .sp
  815. .EX
  816. django\-admin makemessages \-\-locale=de \-\-symlinks
  817. .EE
  818. .UNINDENT
  819. .UNINDENT
  820. .INDENT 0.0
  821. .TP
  822. .B \-\-ignore PATTERN, \-i PATTERN
  823. .UNINDENT
  824. .sp
  825. Ignores files or directories matching the given \X'tty: link https://docs.python.org/3/library/glob.html#module-glob'\fI\%glob\fP\X'tty: link'\-style pattern. Use
  826. multiple times to ignore more.
  827. .sp
  828. These patterns are used by default: \fB\(aqCVS\(aq\fP, \fB\(aq.*\(aq\fP, \fB\(aq*~\(aq\fP, \fB\(aq*.pyc\(aq\fP\&.
  829. .sp
  830. Example usage:
  831. .INDENT 0.0
  832. .INDENT 3.5
  833. .sp
  834. .EX
  835. django\-admin makemessages \-\-locale=en_US \-\-ignore=apps/* \-\-ignore=secret/*.html
  836. .EE
  837. .UNINDENT
  838. .UNINDENT
  839. .INDENT 0.0
  840. .TP
  841. .B \-\-no\-default\-ignore
  842. .UNINDENT
  843. .sp
  844. Disables the default values of \fB\-\-ignore\fP\&.
  845. .INDENT 0.0
  846. .TP
  847. .B \-\-no\-wrap
  848. .UNINDENT
  849. .sp
  850. Disables breaking long message lines into several lines in language files.
  851. .INDENT 0.0
  852. .TP
  853. .B \-\-no\-location
  854. .UNINDENT
  855. .sp
  856. Suppresses writing \(aq\fB#: filename:line\fP’ comment lines in language files.
  857. Using this option makes it harder for technically skilled translators to
  858. understand each message\(aqs context.
  859. .INDENT 0.0
  860. .TP
  861. .B \-\-add\-location [{full,file,never}]
  862. .UNINDENT
  863. .sp
  864. Controls \fB#: filename:line\fP comment lines in language files. If the option
  865. is:
  866. .INDENT 0.0
  867. .IP \(bu 2
  868. \fBfull\fP (the default if not given): the lines include both file name and
  869. line number.
  870. .IP \(bu 2
  871. \fBfile\fP: the line number is omitted.
  872. .IP \(bu 2
  873. \fBnever\fP: the lines are suppressed (same as \fI\%\-\-no\-location\fP).
  874. .UNINDENT
  875. .sp
  876. Requires \fBgettext\fP 0.19 or newer.
  877. .INDENT 0.0
  878. .TP
  879. .B \-\-no\-obsolete
  880. .UNINDENT
  881. .sp
  882. Removes obsolete message strings from the \fB\&.po\fP files.
  883. .INDENT 0.0
  884. .TP
  885. .B \-\-keep\-pot
  886. .UNINDENT
  887. .sp
  888. Prevents deleting the temporary \fB\&.pot\fP files generated before creating the
  889. \fB\&.po\fP file. This is useful for debugging errors which may prevent the final
  890. language files from being created.
  891. .sp
  892. \fBSEE ALSO:\fP
  893. .INDENT 0.0
  894. .INDENT 3.5
  895. See \X'tty: link #customizing-makemessages'\fI\%Customizing the makemessages command\fP\X'tty: link' for instructions on how to customize
  896. the keywords that \fI\%makemessages\fP passes to \fBxgettext\fP\&.
  897. .UNINDENT
  898. .UNINDENT
  899. .SS \fBmakemigrations\fP
  900. .INDENT 0.0
  901. .TP
  902. .B django\-admin makemigrations [app_label [app_label ...]]
  903. .UNINDENT
  904. .sp
  905. Creates new migrations based on the changes detected to your models.
  906. Migrations, their relationship with apps and more are covered in depth in
  907. \fI\%the migrations documentation\fP\&.
  908. .sp
  909. Providing one or more app names as arguments will limit the migrations created
  910. to the app(s) specified and any dependencies needed (the table at the other end
  911. of a \fBForeignKey\fP, for example).
  912. .sp
  913. To add migrations to an app that doesn\(aqt have a \fBmigrations\fP directory, run
  914. \fBmakemigrations\fP with the app\(aqs \fBapp_label\fP\&.
  915. .INDENT 0.0
  916. .TP
  917. .B \-\-noinput, \-\-no\-input
  918. .UNINDENT
  919. .sp
  920. Suppresses all user prompts. If a suppressed prompt cannot be resolved
  921. automatically, the command will exit with error code 3.
  922. .INDENT 0.0
  923. .TP
  924. .B \-\-empty
  925. .UNINDENT
  926. .sp
  927. Outputs an empty migration for the specified apps, for manual editing. This is
  928. for advanced users and should not be used unless you are familiar with the
  929. migration format, migration operations, and the dependencies between your
  930. migrations.
  931. .INDENT 0.0
  932. .TP
  933. .B \-\-dry\-run
  934. .UNINDENT
  935. .sp
  936. Shows what migrations would be made without actually writing any migrations
  937. files to disk. Using this option along with \fB\-\-verbosity 3\fP will also show
  938. the complete migrations files that would be written.
  939. .INDENT 0.0
  940. .TP
  941. .B \-\-merge
  942. .UNINDENT
  943. .sp
  944. Enables fixing of migration conflicts.
  945. .INDENT 0.0
  946. .TP
  947. .B \-\-name NAME, \-n NAME
  948. .UNINDENT
  949. .sp
  950. Allows naming the generated migration(s) instead of using a generated name. The
  951. name must be a valid Python \X'tty: link https://docs.python.org/3/reference/lexical_analysis.html#identifiers'\fI\%identifier\fP\X'tty: link'\&.
  952. .INDENT 0.0
  953. .TP
  954. .B \-\-no\-header
  955. .UNINDENT
  956. .sp
  957. Generate migration files without Django version and timestamp header.
  958. .INDENT 0.0
  959. .TP
  960. .B \-\-check
  961. .UNINDENT
  962. .sp
  963. Makes \fBmakemigrations\fP exit with a non\-zero status when model changes without
  964. migrations are detected. Implies \fB\-\-dry\-run\fP\&.
  965. .INDENT 0.0
  966. .TP
  967. .B \-\-scriptable
  968. .UNINDENT
  969. .sp
  970. Diverts log output and input prompts to \fBstderr\fP, writing only paths of
  971. generated migration files to \fBstdout\fP\&.
  972. .INDENT 0.0
  973. .TP
  974. .B \-\-update
  975. .UNINDENT
  976. .sp
  977. Merges model changes into the latest migration and optimize the resulting
  978. operations.
  979. .sp
  980. The updated migration will have a generated name. In order to preserve the
  981. previous name, set it using \fB\-\-name\fP\&.
  982. .SS \fBmigrate\fP
  983. .INDENT 0.0
  984. .TP
  985. .B django\-admin migrate [app_label] [migration_name]
  986. .UNINDENT
  987. .sp
  988. Synchronizes the database state with the current set of models and migrations.
  989. Migrations, their relationship with apps and more are covered in depth in
  990. \fI\%the migrations documentation\fP\&.
  991. .sp
  992. The behavior of this command changes depending on the arguments provided:
  993. .INDENT 0.0
  994. .IP \(bu 2
  995. No arguments: All apps have all of their migrations run.
  996. .IP \(bu 2
  997. \fB<app_label>\fP: The specified app has its migrations run, up to the most
  998. recent migration. This may involve running other apps\(aq migrations too, due
  999. to dependencies.
  1000. .IP \(bu 2
  1001. \fB<app_label> <migrationname>\fP: Brings the database schema to a state where
  1002. the named migration is applied, but no later migrations in the same app are
  1003. applied. This may involve unapplying migrations if you have previously
  1004. migrated past the named migration. You can use a prefix of the migration
  1005. name, e.g. \fB0001\fP, as long as it\(aqs unique for the given app name. Use the
  1006. name \fBzero\fP to migrate all the way back i.e. to revert all applied
  1007. migrations for an app.
  1008. .UNINDENT
  1009. .sp
  1010. \fBWARNING:\fP
  1011. .INDENT 0.0
  1012. .INDENT 3.5
  1013. When unapplying migrations, all dependent migrations will also be
  1014. unapplied, regardless of \fB<app_label>\fP\&. You can use \fB\-\-plan\fP to check
  1015. which migrations will be unapplied.
  1016. .UNINDENT
  1017. .UNINDENT
  1018. .INDENT 0.0
  1019. .TP
  1020. .B \-\-database DATABASE
  1021. .UNINDENT
  1022. .sp
  1023. Specifies the database to migrate. Defaults to \fBdefault\fP\&.
  1024. .INDENT 0.0
  1025. .TP
  1026. .B \-\-fake
  1027. .UNINDENT
  1028. .sp
  1029. Marks the migrations up to the target one (following the rules above) as
  1030. applied, but without actually running the SQL to change your database schema.
  1031. .sp
  1032. This is intended for advanced users to manipulate the
  1033. current migration state directly if they\(aqre manually applying changes;
  1034. be warned that using \fB\-\-fake\fP runs the risk of putting the migration state
  1035. table into a state where manual recovery will be needed to make migrations
  1036. run correctly.
  1037. .INDENT 0.0
  1038. .TP
  1039. .B \-\-fake\-initial
  1040. .UNINDENT
  1041. .sp
  1042. Allows Django to skip an app\(aqs initial migration if all database tables with
  1043. the names of all models created by all
  1044. \X'tty: link #django.db.migrations.operations.CreateModel'\fI\%CreateModel\fP\X'tty: link' operations in that
  1045. migration already exist. This option is intended for use when first running
  1046. migrations against a database that preexisted the use of migrations. This
  1047. option does not, however, check for matching database schema beyond matching
  1048. table names and so is only safe to use if you are confident that your existing
  1049. schema matches what is recorded in your initial migration.
  1050. .INDENT 0.0
  1051. .TP
  1052. .B \-\-plan
  1053. .UNINDENT
  1054. .sp
  1055. Shows the migration operations that will be performed for the given \fBmigrate\fP
  1056. command.
  1057. .INDENT 0.0
  1058. .TP
  1059. .B \-\-run\-syncdb
  1060. .UNINDENT
  1061. .sp
  1062. Allows creating tables for apps without migrations. While this isn\(aqt
  1063. recommended, the migrations framework is sometimes too slow on large projects
  1064. with hundreds of models.
  1065. .INDENT 0.0
  1066. .TP
  1067. .B \-\-noinput, \-\-no\-input
  1068. .UNINDENT
  1069. .sp
  1070. Suppresses all user prompts. An example prompt is asking about removing stale
  1071. content types.
  1072. .INDENT 0.0
  1073. .TP
  1074. .B \-\-check
  1075. .UNINDENT
  1076. .sp
  1077. Makes \fBmigrate\fP exit with a non\-zero status when unapplied migrations are
  1078. detected.
  1079. .INDENT 0.0
  1080. .TP
  1081. .B \-\-prune
  1082. .UNINDENT
  1083. .sp
  1084. Deletes nonexistent migrations from the \fBdjango_migrations\fP table. This is
  1085. useful when migration files replaced by a squashed migration have been removed.
  1086. See \X'tty: link #migration-squashing'\fI\%Squashing migrations\fP\X'tty: link' for more details.
  1087. .SS \fBoptimizemigration\fP
  1088. .INDENT 0.0
  1089. .TP
  1090. .B django\-admin optimizemigration app_label migration_name
  1091. .UNINDENT
  1092. .sp
  1093. Optimizes the operations for the named migration and overrides the existing
  1094. file. If the migration contains functions that must be manually copied, the
  1095. command creates a new migration file suffixed with \fB_optimized\fP that is meant
  1096. to replace the named migration.
  1097. .INDENT 0.0
  1098. .TP
  1099. .B \-\-check
  1100. .UNINDENT
  1101. .sp
  1102. Makes \fBoptimizemigration\fP exit with a non\-zero status when a migration can be
  1103. optimized.
  1104. .SS \fBrunserver\fP
  1105. .INDENT 0.0
  1106. .TP
  1107. .B django\-admin runserver [addrport]
  1108. .UNINDENT
  1109. .sp
  1110. Starts a lightweight development web server on the local machine. By default,
  1111. the server runs on port 8000 on the IP address \fB127.0.0.1\fP\&. You can pass in an
  1112. IP address and port number explicitly.
  1113. .sp
  1114. If you run this script as a user with normal privileges (recommended), you
  1115. might not have access to start a port on a low port number. Low port numbers
  1116. are reserved for the superuser (root).
  1117. .sp
  1118. This server uses the WSGI application object specified by the
  1119. \X'tty: link #std-setting-WSGI_APPLICATION'\fI\%WSGI_APPLICATION\fP\X'tty: link' setting.
  1120. .sp
  1121. DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through
  1122. security audits or performance tests. (And that\(aqs how it\(aqs gonna stay. We\(aqre in
  1123. the business of making web frameworks, not web servers, so improving this
  1124. server to be able to handle a production environment is outside the scope of
  1125. Django.)
  1126. .sp
  1127. The development server automatically reloads Python code for each request, as
  1128. needed. You don\(aqt need to restart the server for code changes to take effect.
  1129. However, some actions like adding files don\(aqt trigger a restart, so you\(aqll
  1130. have to restart the server in these cases.
  1131. .sp
  1132. If you\(aqre using Linux or MacOS and install both \X'tty: link https://pypi.org/project/pywatchman/'\fI\%pywatchman\fP\X'tty: link' and the
  1133. \X'tty: link https://facebook.github.io/watchman/'\fI\%Watchman\fP\X'tty: link' service, kernel signals will be used to autoreload the server
  1134. (rather than polling file modification timestamps each second). This offers
  1135. better performance on large projects, reduced response time after code changes,
  1136. more robust change detection, and a reduction in power usage. Django supports
  1137. \fBpywatchman\fP 1.2.0 and higher.
  1138. .INDENT 0.0
  1139. .INDENT 3.5
  1140. .IP "Large directories with many files may cause performance issues"
  1141. .sp
  1142. When using Watchman with a project that includes large non\-Python
  1143. directories like \fBnode_modules\fP, it\(aqs advisable to ignore this directory
  1144. for optimal performance. See the \X'tty: link https://facebook.github.io/watchman/docs/config#ignore_dirs'\fI\%watchman documentation\fP\X'tty: link' for information
  1145. on how to do this.
  1146. .UNINDENT
  1147. .UNINDENT
  1148. .INDENT 0.0
  1149. .INDENT 3.5
  1150. .IP "Watchman timeout"
  1151. .INDENT 0.0
  1152. .TP
  1153. .B DJANGO_WATCHMAN_TIMEOUT
  1154. .UNINDENT
  1155. .sp
  1156. The default timeout of \fBWatchman\fP client is 5 seconds. You can change it
  1157. by setting the \fI\%DJANGO_WATCHMAN_TIMEOUT\fP environment variable.
  1158. .UNINDENT
  1159. .UNINDENT
  1160. .sp
  1161. When you start the server, and each time you change Python code while the
  1162. server is running, the system check framework will check your entire Django
  1163. project for some common errors (see the \fI\%check\fP command). If any
  1164. errors are found, they will be printed to standard output. You can use the
  1165. \fB\-\-skip\-checks\fP option to skip running system checks.
  1166. .sp
  1167. You can run as many concurrent servers as you want, as long as they\(aqre on
  1168. separate ports by executing \fBdjango\-admin runserver\fP more than once.
  1169. .sp
  1170. Note that the default IP address, \fB127.0.0.1\fP, is not accessible from other
  1171. machines on your network. To make your development server viewable to other
  1172. machines on the network, use its own IP address (e.g. \fB192.168.2.1\fP), \fB0\fP
  1173. (shortcut for \fB0.0.0.0\fP), \fB0.0.0.0\fP, or \fB::\fP (with IPv6 enabled).
  1174. .sp
  1175. You can provide an IPv6 address surrounded by brackets
  1176. (e.g. \fB[200a::1]:8000\fP). This will automatically enable IPv6 support.
  1177. .sp
  1178. A hostname containing ASCII\-only characters can also be used.
  1179. .sp
  1180. If the \fI\%staticfiles\fP contrib app is enabled
  1181. (default in new projects) the \fI\%runserver\fP command will be overridden
  1182. with its own \X'tty: link #staticfiles-runserver'\fI\%runserver\fP\X'tty: link' command.
  1183. .sp
  1184. Logging of each request and response of the server is sent to the
  1185. \X'tty: link #django-server-logger'\fI\%django.server\fP\X'tty: link' logger.
  1186. .INDENT 0.0
  1187. .TP
  1188. .B \-\-noreload
  1189. .UNINDENT
  1190. .sp
  1191. Disables the auto\-reloader. This means any Python code changes you make while
  1192. the server is running will \fInot\fP take effect if the particular Python modules
  1193. have already been loaded into memory.
  1194. .INDENT 0.0
  1195. .TP
  1196. .B \-\-nothreading
  1197. .UNINDENT
  1198. .sp
  1199. Disables use of threading in the development server. The server is
  1200. multithreaded by default.
  1201. .INDENT 0.0
  1202. .TP
  1203. .B \-\-ipv6, \-6
  1204. .UNINDENT
  1205. .sp
  1206. Uses IPv6 for the development server. This changes the default IP address from
  1207. \fB127.0.0.1\fP to \fB::1\fP\&.
  1208. .SS Examples of using different ports and addresses
  1209. .sp
  1210. Port 8000 on IP address \fB127.0.0.1\fP:
  1211. .INDENT 0.0
  1212. .INDENT 3.5
  1213. .sp
  1214. .EX
  1215. django\-admin runserver
  1216. .EE
  1217. .UNINDENT
  1218. .UNINDENT
  1219. .sp
  1220. Port 8000 on IP address \fB1.2.3.4\fP:
  1221. .INDENT 0.0
  1222. .INDENT 3.5
  1223. .sp
  1224. .EX
  1225. django\-admin runserver 1.2.3.4:8000
  1226. .EE
  1227. .UNINDENT
  1228. .UNINDENT
  1229. .sp
  1230. Port 7000 on IP address \fB127.0.0.1\fP:
  1231. .INDENT 0.0
  1232. .INDENT 3.5
  1233. .sp
  1234. .EX
  1235. django\-admin runserver 7000
  1236. .EE
  1237. .UNINDENT
  1238. .UNINDENT
  1239. .sp
  1240. Port 7000 on IP address \fB1.2.3.4\fP:
  1241. .INDENT 0.0
  1242. .INDENT 3.5
  1243. .sp
  1244. .EX
  1245. django\-admin runserver 1.2.3.4:7000
  1246. .EE
  1247. .UNINDENT
  1248. .UNINDENT
  1249. .sp
  1250. Port 8000 on IPv6 address \fB::1\fP:
  1251. .INDENT 0.0
  1252. .INDENT 3.5
  1253. .sp
  1254. .EX
  1255. django\-admin runserver \-6
  1256. .EE
  1257. .UNINDENT
  1258. .UNINDENT
  1259. .sp
  1260. Port 7000 on IPv6 address \fB::1\fP:
  1261. .INDENT 0.0
  1262. .INDENT 3.5
  1263. .sp
  1264. .EX
  1265. django\-admin runserver \-6 7000
  1266. .EE
  1267. .UNINDENT
  1268. .UNINDENT
  1269. .sp
  1270. Port 7000 on IPv6 address \fB2001:0db8:1234:5678::9\fP:
  1271. .INDENT 0.0
  1272. .INDENT 3.5
  1273. .sp
  1274. .EX
  1275. django\-admin runserver [2001:0db8:1234:5678::9]:7000
  1276. .EE
  1277. .UNINDENT
  1278. .UNINDENT
  1279. .sp
  1280. Port 8000 on IPv4 address of host \fBlocalhost\fP:
  1281. .INDENT 0.0
  1282. .INDENT 3.5
  1283. .sp
  1284. .EX
  1285. django\-admin runserver localhost:8000
  1286. .EE
  1287. .UNINDENT
  1288. .UNINDENT
  1289. .sp
  1290. Port 8000 on IPv6 address of host \fBlocalhost\fP:
  1291. .INDENT 0.0
  1292. .INDENT 3.5
  1293. .sp
  1294. .EX
  1295. django\-admin runserver \-6 localhost:8000
  1296. .EE
  1297. .UNINDENT
  1298. .UNINDENT
  1299. .SS Serving static files with the development server
  1300. .sp
  1301. By default, the development server doesn\(aqt serve any static files for your site
  1302. (such as CSS files, images, things under \X'tty: link #std-setting-MEDIA_URL'\fI\%MEDIA_URL\fP\X'tty: link' and so forth). If
  1303. you want to configure Django to serve static media, read
  1304. \fI\%How to manage static files (e.g. images, JavaScript, CSS)\fP\&.
  1305. .SS Serving with ASGI in development
  1306. .sp
  1307. Django\(aqs \fBrunserver\fP command provides a WSGI server. In order to run under
  1308. ASGI you will need to use an \fI\%ASGI server\fP\&.
  1309. The Django Daphne project provides \X'tty: link #daphne-runserver'\fI\%Integration with runserver\fP\X'tty: link' that you can use.
  1310. .SS \fBsendtestemail\fP
  1311. .INDENT 0.0
  1312. .TP
  1313. .B django\-admin sendtestemail [email [email ...]]
  1314. .UNINDENT
  1315. .sp
  1316. Sends a test email (to confirm email sending through Django is working) to the
  1317. recipient(s) specified. For example:
  1318. .INDENT 0.0
  1319. .INDENT 3.5
  1320. .sp
  1321. .EX
  1322. django\-admin sendtestemail foo@example.com bar@example.com
  1323. .EE
  1324. .UNINDENT
  1325. .UNINDENT
  1326. .sp
  1327. There are a couple of options, and you may use any combination of them
  1328. together:
  1329. .INDENT 0.0
  1330. .TP
  1331. .B \-\-managers
  1332. .UNINDENT
  1333. .sp
  1334. Mails the email addresses specified in \X'tty: link #std-setting-MANAGERS'\fI\%MANAGERS\fP\X'tty: link' using
  1335. \X'tty: link #django.core.mail.mail_managers'\fI\%mail_managers()\fP\X'tty: link'\&.
  1336. .INDENT 0.0
  1337. .TP
  1338. .B \-\-admins
  1339. .UNINDENT
  1340. .sp
  1341. Mails the email addresses specified in \X'tty: link #std-setting-ADMINS'\fI\%ADMINS\fP\X'tty: link' using
  1342. \X'tty: link #django.core.mail.mail_admins'\fI\%mail_admins()\fP\X'tty: link'\&.
  1343. .SS \fBshell\fP
  1344. .INDENT 0.0
  1345. .TP
  1346. .B django\-admin shell
  1347. .UNINDENT
  1348. .sp
  1349. Starts the Python interactive interpreter.
  1350. .INDENT 0.0
  1351. .TP
  1352. .B \-\-interface {ipython,bpython,python}, \-i {ipython,bpython,python}
  1353. .UNINDENT
  1354. .sp
  1355. Specifies the shell to use. By default, Django will use \X'tty: link https://ipython.org/'\fI\%IPython\fP\X'tty: link' or \X'tty: link https://bpython-interpreter.org/'\fI\%bpython\fP\X'tty: link' if
  1356. either is installed. If both are installed, specify which one you want like so:
  1357. .sp
  1358. IPython:
  1359. .INDENT 0.0
  1360. .INDENT 3.5
  1361. .sp
  1362. .EX
  1363. django\-admin shell \-i ipython
  1364. .EE
  1365. .UNINDENT
  1366. .UNINDENT
  1367. .sp
  1368. bpython:
  1369. .INDENT 0.0
  1370. .INDENT 3.5
  1371. .sp
  1372. .EX
  1373. django\-admin shell \-i bpython
  1374. .EE
  1375. .UNINDENT
  1376. .UNINDENT
  1377. .sp
  1378. If you have a \(dqrich\(dq shell installed but want to force use of the \(dqplain\(dq
  1379. Python interpreter, use \fBpython\fP as the interface name, like so:
  1380. .INDENT 0.0
  1381. .INDENT 3.5
  1382. .sp
  1383. .EX
  1384. django\-admin shell \-i python
  1385. .EE
  1386. .UNINDENT
  1387. .UNINDENT
  1388. .INDENT 0.0
  1389. .TP
  1390. .B \-\-nostartup
  1391. .UNINDENT
  1392. .sp
  1393. Disables reading the startup script for the \(dqplain\(dq Python interpreter. By
  1394. default, the script pointed to by the \X'tty: link https://docs.python.org/3/using/cmdline.html#envvar-PYTHONSTARTUP'\fI\%PYTHONSTARTUP\fP\X'tty: link' environment
  1395. variable or the \fB~/.pythonrc.py\fP script is read.
  1396. .INDENT 0.0
  1397. .TP
  1398. .B \-\-command COMMAND, \-c COMMAND
  1399. .UNINDENT
  1400. .sp
  1401. Lets you pass a command as a string to execute it as Django, like so:
  1402. .INDENT 0.0
  1403. .INDENT 3.5
  1404. .sp
  1405. .EX
  1406. django\-admin shell \-\-command=\(dqimport django; print(django.__version__)\(dq
  1407. .EE
  1408. .UNINDENT
  1409. .UNINDENT
  1410. .sp
  1411. You can also pass code in on standard input to execute it. For example:
  1412. .INDENT 0.0
  1413. .INDENT 3.5
  1414. .sp
  1415. .EX
  1416. $ django\-admin shell <<EOF
  1417. > import django
  1418. > print(django.__version__)
  1419. > EOF
  1420. .EE
  1421. .UNINDENT
  1422. .UNINDENT
  1423. .sp
  1424. On Windows, the REPL is output due to implementation limits of
  1425. \X'tty: link https://docs.python.org/3/library/select.html#select.select'\fI\%select.select()\fP\X'tty: link' on that platform.
  1426. .SS \fBshowmigrations\fP
  1427. .INDENT 0.0
  1428. .TP
  1429. .B django\-admin showmigrations [app_label [app_label ...]]
  1430. .UNINDENT
  1431. .sp
  1432. Shows all migrations in a project. You can choose from one of two formats:
  1433. .INDENT 0.0
  1434. .TP
  1435. .B \-\-list, \-l
  1436. .UNINDENT
  1437. .sp
  1438. Lists all of the apps Django knows about, the migrations available for each
  1439. app, and whether or not each migration is applied (marked by an \fB[X]\fP next to
  1440. the migration name). For a \fB\-\-verbosity\fP of 2 and above, the applied
  1441. datetimes are also shown.
  1442. .sp
  1443. Apps without migrations are also listed, but have \fB(no migrations)\fP printed
  1444. under them.
  1445. .sp
  1446. This is the default output format.
  1447. .INDENT 0.0
  1448. .TP
  1449. .B \-\-plan, \-p
  1450. .UNINDENT
  1451. .sp
  1452. Shows the migration plan Django will follow to apply migrations. Like
  1453. \fB\-\-list\fP, applied migrations are marked by an \fB[X]\fP\&. For a \fB\-\-verbosity\fP
  1454. of 2 and above, all dependencies of a migration will also be shown.
  1455. .sp
  1456. \fBapp_label\fPs arguments limit the output, however, dependencies of provided
  1457. apps may also be included.
  1458. .INDENT 0.0
  1459. .TP
  1460. .B \-\-database DATABASE
  1461. .UNINDENT
  1462. .sp
  1463. Specifies the database to examine. Defaults to \fBdefault\fP\&.
  1464. .SS \fBsqlflush\fP
  1465. .INDENT 0.0
  1466. .TP
  1467. .B django\-admin sqlflush
  1468. .UNINDENT
  1469. .sp
  1470. Prints the SQL statements that would be executed for the \fI\%flush\fP
  1471. command.
  1472. .INDENT 0.0
  1473. .TP
  1474. .B \-\-database DATABASE
  1475. .UNINDENT
  1476. .sp
  1477. Specifies the database for which to print the SQL. Defaults to \fBdefault\fP\&.
  1478. .SS \fBsqlmigrate\fP
  1479. .INDENT 0.0
  1480. .TP
  1481. .B django\-admin sqlmigrate app_label migration_name
  1482. .UNINDENT
  1483. .sp
  1484. Prints the SQL for the named migration. This requires an active database
  1485. connection, which it will use to resolve constraint names; this means you must
  1486. generate the SQL against a copy of the database you wish to later apply it on.
  1487. .sp
  1488. Note that \fBsqlmigrate\fP doesn\(aqt colorize its output.
  1489. .INDENT 0.0
  1490. .TP
  1491. .B \-\-backwards
  1492. .UNINDENT
  1493. .sp
  1494. Generates the SQL for unapplying the migration. By default, the SQL created is
  1495. for running the migration in the forwards direction.
  1496. .INDENT 0.0
  1497. .TP
  1498. .B \-\-database DATABASE
  1499. .UNINDENT
  1500. .sp
  1501. Specifies the database for which to generate the SQL. Defaults to \fBdefault\fP\&.
  1502. .SS \fBsqlsequencereset\fP
  1503. .INDENT 0.0
  1504. .TP
  1505. .B django\-admin sqlsequencereset app_label [app_label ...]
  1506. .UNINDENT
  1507. .sp
  1508. Prints the SQL statements for resetting sequences for the given app name(s).
  1509. .sp
  1510. Sequences are indexes used by some database engines to track the next available
  1511. number for automatically incremented fields.
  1512. .sp
  1513. Use this command to generate SQL which will fix cases where a sequence is out
  1514. of sync with its automatically incremented field data.
  1515. .INDENT 0.0
  1516. .TP
  1517. .B \-\-database DATABASE
  1518. .UNINDENT
  1519. .sp
  1520. Specifies the database for which to print the SQL. Defaults to \fBdefault\fP\&.
  1521. .SS \fBsquashmigrations\fP
  1522. .INDENT 0.0
  1523. .TP
  1524. .B django\-admin squashmigrations app_label [start_migration_name] migration_name
  1525. .UNINDENT
  1526. .sp
  1527. Squashes the migrations for \fBapp_label\fP up to and including \fBmigration_name\fP
  1528. down into fewer migrations, if possible. The resulting squashed migrations
  1529. can live alongside the unsquashed ones safely. For more information,
  1530. please read \X'tty: link #migration-squashing'\fI\%Squashing migrations\fP\X'tty: link'\&.
  1531. .sp
  1532. When \fBstart_migration_name\fP is given, Django will only include migrations
  1533. starting from and including this migration. This helps to mitigate the
  1534. squashing limitation of \X'tty: link #django.db.migrations.operations.RunPython'\fI\%RunPython\fP\X'tty: link' and
  1535. \X'tty: link #django.db.migrations.operations.RunSQL'\fI\%django.db.migrations.operations.RunSQL\fP\X'tty: link' migration operations.
  1536. .INDENT 0.0
  1537. .TP
  1538. .B \-\-no\-optimize
  1539. .UNINDENT
  1540. .sp
  1541. Disables the optimizer when generating a squashed migration. By default, Django
  1542. will try to optimize the operations in your migrations to reduce the size of
  1543. the resulting file. Use this option if this process is failing or creating
  1544. incorrect migrations, though please also file a Django bug report about the
  1545. behavior, as optimization is meant to be safe.
  1546. .INDENT 0.0
  1547. .TP
  1548. .B \-\-noinput, \-\-no\-input
  1549. .UNINDENT
  1550. .sp
  1551. Suppresses all user prompts.
  1552. .INDENT 0.0
  1553. .TP
  1554. .B \-\-squashed\-name SQUASHED_NAME
  1555. .UNINDENT
  1556. .sp
  1557. Sets the name of the squashed migration. When omitted, the name is based on the
  1558. first and last migration, with \fB_squashed_\fP in between.
  1559. .INDENT 0.0
  1560. .TP
  1561. .B \-\-no\-header
  1562. .UNINDENT
  1563. .sp
  1564. Generate squashed migration file without Django version and timestamp header.
  1565. .SS \fBstartapp\fP
  1566. .INDENT 0.0
  1567. .TP
  1568. .B django\-admin startapp name [directory]
  1569. .UNINDENT
  1570. .sp
  1571. Creates a Django app directory structure for the given app name in the current
  1572. directory or the given destination.
  1573. .sp
  1574. By default, \X'tty: link https://github.com/django/django/blob/main/django/conf/app_template'\fI\%the new directory\fP\X'tty: link' contains a
  1575. \fBmodels.py\fP file and other app template files. If only the app name is given,
  1576. the app directory will be created in the current working directory.
  1577. .sp
  1578. If the optional destination is provided, Django will use that existing
  1579. directory rather than creating a new one. You can use \(aq.\(aq to denote the current
  1580. working directory.
  1581. .sp
  1582. For example:
  1583. .INDENT 0.0
  1584. .INDENT 3.5
  1585. .sp
  1586. .EX
  1587. django\-admin startapp myapp /Users/jezdez/Code/myapp
  1588. .EE
  1589. .UNINDENT
  1590. .UNINDENT
  1591. .INDENT 0.0
  1592. .TP
  1593. .B \-\-template TEMPLATE
  1594. .UNINDENT
  1595. .sp
  1596. Provides the path to a directory with a custom app template file, or a path to
  1597. an uncompressed archive (\fB\&.tar\fP) or a compressed archive (\fB\&.tar.gz\fP,
  1598. \fB\&.tar.bz2\fP, \fB\&.tar.xz\fP, \fB\&.tar.lzma\fP, \fB\&.tgz\fP, \fB\&.tbz2\fP, \fB\&.txz\fP,
  1599. \fB\&.tlz\fP, \fB\&.zip\fP) containing the app template files.
  1600. .sp
  1601. For example, this would look for an app template in the given directory when
  1602. creating the \fBmyapp\fP app:
  1603. .INDENT 0.0
  1604. .INDENT 3.5
  1605. .sp
  1606. .EX
  1607. django\-admin startapp \-\-template=/Users/jezdez/Code/my_app_template myapp
  1608. .EE
  1609. .UNINDENT
  1610. .UNINDENT
  1611. .sp
  1612. Django will also accept URLs (\fBhttp\fP, \fBhttps\fP, \fBftp\fP) to compressed
  1613. archives with the app template files, downloading and extracting them on the
  1614. fly.
  1615. .sp
  1616. For example, taking advantage of GitHub\(aqs feature to expose repositories as
  1617. zip files, you can use a URL like:
  1618. .INDENT 0.0
  1619. .INDENT 3.5
  1620. .sp
  1621. .EX
  1622. django\-admin startapp \-\-template=https://github.com/githubuser/django\-app\-template/archive/main.zip myapp
  1623. .EE
  1624. .UNINDENT
  1625. .UNINDENT
  1626. .INDENT 0.0
  1627. .TP
  1628. .B \-\-extension EXTENSIONS, \-e EXTENSIONS
  1629. .UNINDENT
  1630. .sp
  1631. Specifies which file extensions in the app template should be rendered with the
  1632. template engine. Defaults to \fBpy\fP\&.
  1633. .INDENT 0.0
  1634. .TP
  1635. .B \-\-name FILES, \-n FILES
  1636. .UNINDENT
  1637. .sp
  1638. Specifies which files in the app template (in addition to those matching
  1639. \fB\-\-extension\fP) should be rendered with the template engine. Defaults to an
  1640. empty list.
  1641. .INDENT 0.0
  1642. .TP
  1643. .B \-\-exclude DIRECTORIES, \-x DIRECTORIES
  1644. .UNINDENT
  1645. .sp
  1646. Specifies which directories in the app template should be excluded, in addition
  1647. to \fB\&.git\fP and \fB__pycache__\fP\&. If this option is not provided, directories
  1648. named \fB__pycache__\fP or starting with \fB\&.\fP will be excluded.
  1649. .sp
  1650. The \X'tty: link #django.template.Context'\fI\%template context\fP\X'tty: link' used for all matching
  1651. files is:
  1652. .INDENT 0.0
  1653. .IP \(bu 2
  1654. Any option passed to the \fBstartapp\fP command (among the command\(aqs supported
  1655. options)
  1656. .IP \(bu 2
  1657. \fBapp_name\fP \-\- the app name as passed to the command
  1658. .IP \(bu 2
  1659. \fBapp_directory\fP \-\- the full path of the newly created app
  1660. .IP \(bu 2
  1661. \fBcamel_case_app_name\fP \-\- the app name in camel case format
  1662. .IP \(bu 2
  1663. \fBdocs_version\fP \-\- the version of the documentation: \fB\(aqdev\(aq\fP or \fB\(aq1.x\(aq\fP
  1664. .IP \(bu 2
  1665. \fBdjango_version\fP \-\- the version of Django, e.g. \fB\(aq2.0.3\(aq\fP
  1666. .UNINDENT
  1667. .sp
  1668. \fBWARNING:\fP
  1669. .INDENT 0.0
  1670. .INDENT 3.5
  1671. When the app template files are rendered with the Django template
  1672. engine (by default all \fB*.py\fP files), Django will also replace all
  1673. stray template variables contained. For example, if one of the Python files
  1674. contains a docstring explaining a particular feature related
  1675. to template rendering, it might result in an incorrect example.
  1676. .sp
  1677. To work around this problem, you can use the \X'tty: link #std-templatetag-templatetag'\fI\%templatetag\fP\X'tty: link'
  1678. template tag to \(dqescape\(dq the various parts of the template syntax.
  1679. .sp
  1680. In addition, to allow Python template files that contain Django template
  1681. language syntax while also preventing packaging systems from trying to
  1682. byte\-compile invalid \fB*.py\fP files, template files ending with \fB\&.py\-tpl\fP
  1683. will be renamed to \fB\&.py\fP\&.
  1684. .UNINDENT
  1685. .UNINDENT
  1686. .sp
  1687. \fBWARNING:\fP
  1688. .INDENT 0.0
  1689. .INDENT 3.5
  1690. The contents of custom app (or project) templates should always be
  1691. audited before use: Such templates define code that will become
  1692. part of your project, and this means that such code will be trusted
  1693. as much as any app you install, or code you write yourself.
  1694. Further, even rendering the templates is, effectively, executing
  1695. code that was provided as input to the management command. The
  1696. Django template language may provide wide access into the system,
  1697. so make sure any custom template you use is worthy of your trust.
  1698. .UNINDENT
  1699. .UNINDENT
  1700. .SS \fBstartproject\fP
  1701. .INDENT 0.0
  1702. .TP
  1703. .B django\-admin startproject name [directory]
  1704. .UNINDENT
  1705. .sp
  1706. Creates a Django project directory structure for the given project name in
  1707. the current directory or the given destination.
  1708. .sp
  1709. By default, \X'tty: link https://github.com/django/django/blob/main/django/conf/project_template'\fI\%the new directory\fP\X'tty: link' contains
  1710. \fBmanage.py\fP and a project package (containing a \fBsettings.py\fP and other
  1711. files).
  1712. .sp
  1713. If only the project name is given, both the project directory and project
  1714. package will be named \fB<projectname>\fP and the project directory
  1715. will be created in the current working directory.
  1716. .sp
  1717. If the optional destination is provided, Django will use that existing
  1718. directory as the project directory, and create \fBmanage.py\fP and the project
  1719. package within it. Use \(aq.\(aq to denote the current working directory.
  1720. .sp
  1721. For example:
  1722. .INDENT 0.0
  1723. .INDENT 3.5
  1724. .sp
  1725. .EX
  1726. django\-admin startproject myproject /Users/jezdez/Code/myproject_repo
  1727. .EE
  1728. .UNINDENT
  1729. .UNINDENT
  1730. .INDENT 0.0
  1731. .TP
  1732. .B \-\-template TEMPLATE
  1733. .UNINDENT
  1734. .sp
  1735. Specifies a directory, file path, or URL of a custom project template. See the
  1736. \fI\%startapp \-\-template\fP documentation for examples and usage.
  1737. .INDENT 0.0
  1738. .TP
  1739. .B \-\-extension EXTENSIONS, \-e EXTENSIONS
  1740. .UNINDENT
  1741. .sp
  1742. Specifies which file extensions in the project template should be rendered with
  1743. the template engine. Defaults to \fBpy\fP\&.
  1744. .INDENT 0.0
  1745. .TP
  1746. .B \-\-name FILES, \-n FILES
  1747. .UNINDENT
  1748. .sp
  1749. Specifies which files in the project template (in addition to those matching
  1750. \fB\-\-extension\fP) should be rendered with the template engine. Defaults to an
  1751. empty list.
  1752. .INDENT 0.0
  1753. .TP
  1754. .B \-\-exclude DIRECTORIES, \-x DIRECTORIES
  1755. .UNINDENT
  1756. .sp
  1757. Specifies which directories in the project template should be excluded, in
  1758. addition to \fB\&.git\fP and \fB__pycache__\fP\&. If this option is not provided,
  1759. directories named \fB__pycache__\fP or starting with \fB\&.\fP will be excluded.
  1760. .sp
  1761. The \X'tty: link #django.template.Context'\fI\%template context\fP\X'tty: link' used is:
  1762. .INDENT 0.0
  1763. .IP \(bu 2
  1764. Any option passed to the \fBstartproject\fP command (among the command\(aqs
  1765. supported options)
  1766. .IP \(bu 2
  1767. \fBproject_name\fP \-\- the project name as passed to the command
  1768. .IP \(bu 2
  1769. \fBproject_directory\fP \-\- the full path of the newly created project
  1770. .IP \(bu 2
  1771. \fBsecret_key\fP \-\- a random key for the \X'tty: link #std-setting-SECRET_KEY'\fI\%SECRET_KEY\fP\X'tty: link' setting
  1772. .IP \(bu 2
  1773. \fBdocs_version\fP \-\- the version of the documentation: \fB\(aqdev\(aq\fP or \fB\(aq1.x\(aq\fP
  1774. .IP \(bu 2
  1775. \fBdjango_version\fP \-\- the version of Django, e.g. \fB\(aq2.0.3\(aq\fP
  1776. .UNINDENT
  1777. .sp
  1778. Please also see the \fI\%rendering warning\fP and
  1779. \fI\%trusted code warning\fP as mentioned for
  1780. \fI\%startapp\fP\&.
  1781. .SS \fBtest\fP
  1782. .INDENT 0.0
  1783. .TP
  1784. .B django\-admin test [test_label [test_label ...]]
  1785. .UNINDENT
  1786. .sp
  1787. Runs tests for all installed apps. See \fI\%Testing in Django\fP for more
  1788. information.
  1789. .INDENT 0.0
  1790. .TP
  1791. .B \-\-failfast
  1792. .UNINDENT
  1793. .sp
  1794. Stops running tests and reports the failure immediately after a test fails.
  1795. .INDENT 0.0
  1796. .TP
  1797. .B \-\-testrunner TESTRUNNER
  1798. .UNINDENT
  1799. .sp
  1800. Controls the test runner class that is used to execute tests. This value
  1801. overrides the value provided by the \X'tty: link #std-setting-TEST_RUNNER'\fI\%TEST_RUNNER\fP\X'tty: link' setting.
  1802. .INDENT 0.0
  1803. .TP
  1804. .B \-\-noinput, \-\-no\-input
  1805. .UNINDENT
  1806. .sp
  1807. Suppresses all user prompts. A typical prompt is a warning about deleting an
  1808. existing test database.
  1809. .SS Test runner options
  1810. .sp
  1811. The \fBtest\fP command receives options on behalf of the specified
  1812. \fI\%\-\-testrunner\fP\&. These are the options of the default test runner:
  1813. \X'tty: link #django.test.runner.DiscoverRunner'\fI\%DiscoverRunner\fP\X'tty: link'\&.
  1814. .INDENT 0.0
  1815. .TP
  1816. .B \-\-keepdb
  1817. .UNINDENT
  1818. .sp
  1819. Preserves the test database between test runs. This has the advantage of
  1820. skipping both the create and destroy actions which can greatly decrease the
  1821. time to run tests, especially those in a large test suite. If the test database
  1822. does not exist, it will be created on the first run and then preserved for each
  1823. subsequent run. Unless the \X'tty: link #std-setting-TEST_MIGRATE'\fI\%MIGRATE\fP\X'tty: link' test setting is
  1824. \fBFalse\fP, any unapplied migrations will also be applied to the test database
  1825. before running the test suite.
  1826. .INDENT 0.0
  1827. .TP
  1828. .B \-\-shuffle [SEED]
  1829. .UNINDENT
  1830. .sp
  1831. Randomizes the order of tests before running them. This can help detect tests
  1832. that aren\(aqt properly isolated. The test order generated by this option is a
  1833. deterministic function of the integer seed given. When no seed is passed, a
  1834. seed is chosen randomly and printed to the console. To repeat a particular test
  1835. order, pass a seed. The test orders generated by this option preserve Django\(aqs
  1836. \X'tty: link #order-of-tests'\fI\%guarantees on test order\fP\X'tty: link'\&. They also keep tests grouped
  1837. by test case class.
  1838. .sp
  1839. The shuffled orderings also have a special consistency property useful when
  1840. narrowing down isolation issues. Namely, for a given seed and when running a
  1841. subset of tests, the new order will be the original shuffling restricted to the
  1842. smaller set. Similarly, when adding tests while keeping the seed the same, the
  1843. order of the original tests will be the same in the new order.
  1844. .INDENT 0.0
  1845. .TP
  1846. .B \-\-reverse, \-r
  1847. .UNINDENT
  1848. .sp
  1849. Sorts test cases in the opposite execution order. This may help in debugging
  1850. the side effects of tests that aren\(aqt properly isolated. \X'tty: link #order-of-tests'\fI\%Grouping by test
  1851. class\fP\X'tty: link' is preserved when using this option. This can be used
  1852. in conjunction with \fB\-\-shuffle\fP to reverse the order for a particular seed.
  1853. .INDENT 0.0
  1854. .TP
  1855. .B \-\-debug\-mode
  1856. .UNINDENT
  1857. .sp
  1858. Sets the \X'tty: link #std-setting-DEBUG'\fI\%DEBUG\fP\X'tty: link' setting to \fBTrue\fP prior to running tests. This may
  1859. help troubleshoot test failures.
  1860. .INDENT 0.0
  1861. .TP
  1862. .B \-\-debug\-sql, \-d
  1863. .UNINDENT
  1864. .sp
  1865. Enables \X'tty: link #django-db-logger'\fI\%SQL logging\fP\X'tty: link' for failing tests. If
  1866. \fB\-\-verbosity\fP is \fB2\fP, then queries in passing tests are also output.
  1867. .INDENT 0.0
  1868. .TP
  1869. .B \-\-parallel [N]
  1870. .UNINDENT
  1871. .INDENT 0.0
  1872. .TP
  1873. .B DJANGO_TEST_PROCESSES
  1874. .UNINDENT
  1875. .sp
  1876. Runs tests in separate parallel processes. Since modern processors have
  1877. multiple cores, this allows running tests significantly faster.
  1878. .sp
  1879. Using \fB\-\-parallel\fP without a value, or with the value \fBauto\fP, runs one test
  1880. process per core according to \X'tty: link https://docs.python.org/3/library/multiprocessing.html#multiprocessing.cpu_count'\fI\%multiprocessing.cpu_count()\fP\X'tty: link'\&. You can
  1881. override this by passing the desired number of processes, e.g.
  1882. \fB\-\-parallel 4\fP, or by setting the \fI\%DJANGO_TEST_PROCESSES\fP environment
  1883. variable.
  1884. .sp
  1885. Django distributes test cases — \X'tty: link https://docs.python.org/3/library/unittest.html#unittest.TestCase'\fI\%unittest.TestCase\fP\X'tty: link' subclasses — to
  1886. subprocesses. If there are fewer test case classes than configured processes,
  1887. Django will reduce the number of processes accordingly.
  1888. .sp
  1889. Each process gets its own database. You must ensure that different test case
  1890. classes don\(aqt access the same resources. For instance, test case classes that
  1891. touch the filesystem should create a temporary directory for their own use.
  1892. .sp
  1893. \fBNOTE:\fP
  1894. .INDENT 0.0
  1895. .INDENT 3.5
  1896. If you have test classes that cannot be run in parallel, you can use
  1897. \fBSerializeMixin\fP to run them sequentially. See \X'tty: link #topics-testing-enforce-run-sequentially'\fI\%Enforce running test
  1898. classes sequentially\fP\X'tty: link'\&.
  1899. .UNINDENT
  1900. .UNINDENT
  1901. .sp
  1902. This option requires the third\-party \fBtblib\fP package to display tracebacks
  1903. correctly:
  1904. .INDENT 0.0
  1905. .INDENT 3.5
  1906. .sp
  1907. .EX
  1908. $ python \-m pip install tblib
  1909. .EE
  1910. .UNINDENT
  1911. .UNINDENT
  1912. .sp
  1913. This feature isn\(aqt available on Windows. It doesn\(aqt work with the Oracle
  1914. database backend either.
  1915. .sp
  1916. If you want to use \X'tty: link https://docs.python.org/3/library/pdb.html#module-pdb'\fI\%pdb\fP\X'tty: link' while debugging tests, you must disable parallel
  1917. execution (\fB\-\-parallel=1\fP). You\(aqll see something like \fBbdb.BdbQuit\fP if you
  1918. don\(aqt.
  1919. .sp
  1920. \fBWARNING:\fP
  1921. .INDENT 0.0
  1922. .INDENT 3.5
  1923. When test parallelization is enabled and a test fails, Django may be
  1924. unable to display the exception traceback. This can make debugging
  1925. difficult. If you encounter this problem, run the affected test without
  1926. parallelization to see the traceback of the failure.
  1927. .sp
  1928. This is a known limitation. It arises from the need to serialize objects
  1929. in order to exchange them between processes. See
  1930. \X'tty: link https://docs.python.org/3/library/pickle.html#pickle-picklable'\fI\%What can be pickled and unpickled?\fP\X'tty: link' for details.
  1931. .UNINDENT
  1932. .UNINDENT
  1933. .INDENT 0.0
  1934. .TP
  1935. .B \-\-tag TAGS
  1936. .UNINDENT
  1937. .sp
  1938. Runs only tests \X'tty: link #topics-tagging-tests'\fI\%marked with the specified tags\fP\X'tty: link'\&.
  1939. May be specified multiple times and combined with \fI\%test \-\-exclude\-tag\fP\&.
  1940. .sp
  1941. Tests that fail to load are always considered matching.
  1942. .INDENT 0.0
  1943. .TP
  1944. .B \-\-exclude\-tag EXCLUDE_TAGS
  1945. .UNINDENT
  1946. .sp
  1947. Excludes tests \X'tty: link #topics-tagging-tests'\fI\%marked with the specified tags\fP\X'tty: link'\&.
  1948. May be specified multiple times and combined with \fI\%test \-\-tag\fP\&.
  1949. .INDENT 0.0
  1950. .TP
  1951. .B \-k TEST_NAME_PATTERNS
  1952. .UNINDENT
  1953. .sp
  1954. Runs test methods and classes matching test name patterns, in the same way as
  1955. \X'tty: link https://docs.python.org/3/library/unittest.html#cmdoption-unittest-k'\fI\%unittest\(aqs \-k option\fP\X'tty: link'\&. Can be specified multiple times.
  1956. .INDENT 0.0
  1957. .TP
  1958. .B \-\-pdb
  1959. .UNINDENT
  1960. .sp
  1961. Spawns a \fBpdb\fP debugger at each test error or failure. If you have it
  1962. installed, \fBipdb\fP is used instead.
  1963. .INDENT 0.0
  1964. .TP
  1965. .B \-\-buffer, \-b
  1966. .UNINDENT
  1967. .sp
  1968. Discards output (\fBstdout\fP and \fBstderr\fP) for passing tests, in the same way
  1969. as \X'tty: link https://docs.python.org/3/library/unittest.html#cmdoption-unittest-b'\fI\%unittest\(aqs \-\-buffer option\fP\X'tty: link'\&.
  1970. .INDENT 0.0
  1971. .TP
  1972. .B \-\-no\-faulthandler
  1973. .UNINDENT
  1974. .sp
  1975. Django automatically calls \X'tty: link https://docs.python.org/3/library/faulthandler.html#faulthandler.enable'\fI\%faulthandler.enable()\fP\X'tty: link' when starting the
  1976. tests, which allows it to print a traceback if the interpreter crashes. Pass
  1977. \fB\-\-no\-faulthandler\fP to disable this behavior.
  1978. .INDENT 0.0
  1979. .TP
  1980. .B \-\-timing
  1981. .UNINDENT
  1982. .sp
  1983. Outputs timings, including database setup and total run time.
  1984. .INDENT 0.0
  1985. .TP
  1986. .B \-\-durations N
  1987. .UNINDENT
  1988. .sp
  1989. .sp
  1990. Shows the N slowest test cases (N=0 for all).
  1991. .INDENT 0.0
  1992. .INDENT 3.5
  1993. .IP "Python 3.12 and later"
  1994. .sp
  1995. This feature is only available for Python 3.12 and later.
  1996. .UNINDENT
  1997. .UNINDENT
  1998. .SS \fBtestserver\fP
  1999. .INDENT 0.0
  2000. .TP
  2001. .B django\-admin testserver [fixture [fixture ...]]
  2002. .UNINDENT
  2003. .sp
  2004. Runs a Django development server (as in \fI\%runserver\fP) using data from
  2005. the given fixture(s).
  2006. .sp
  2007. For example, this command:
  2008. .INDENT 0.0
  2009. .INDENT 3.5
  2010. .sp
  2011. .EX
  2012. django\-admin testserver mydata.json
  2013. .EE
  2014. .UNINDENT
  2015. .UNINDENT
  2016. .sp
  2017. \&...would perform the following steps:
  2018. .INDENT 0.0
  2019. .IP 1. 3
  2020. Create a test database, as described in \X'tty: link #the-test-database'\fI\%The test database\fP\X'tty: link'\&.
  2021. .IP 2. 3
  2022. Populate the test database with fixture data from the given fixtures.
  2023. (For more on fixtures, see the documentation for \fI\%loaddata\fP above.)
  2024. .IP 3. 3
  2025. Runs the Django development server (as in \fI\%runserver\fP), pointed at
  2026. this newly created test database instead of your production database.
  2027. .UNINDENT
  2028. .sp
  2029. This is useful in a number of ways:
  2030. .INDENT 0.0
  2031. .IP \(bu 2
  2032. When you\(aqre writing \fI\%unit tests\fP of how your views
  2033. act with certain fixture data, you can use \fBtestserver\fP to interact with
  2034. the views in a web browser, manually.
  2035. .IP \(bu 2
  2036. Let\(aqs say you\(aqre developing your Django application and have a \(dqpristine\(dq
  2037. copy of a database that you\(aqd like to interact with. You can dump your
  2038. database to a \X'tty: link #fixtures-explanation'\fI\%fixture\fP\X'tty: link' (using the
  2039. \fI\%dumpdata\fP command, explained above), then use \fBtestserver\fP to run
  2040. your web application with that data. With this arrangement, you have the
  2041. flexibility of messing up your data in any way, knowing that whatever data
  2042. changes you\(aqre making are only being made to a test database.
  2043. .UNINDENT
  2044. .sp
  2045. Note that this server does \fInot\fP automatically detect changes to your Python
  2046. source code (as \fI\%runserver\fP does). It does, however, detect changes to
  2047. templates.
  2048. .INDENT 0.0
  2049. .TP
  2050. .B \-\-addrport ADDRPORT
  2051. .UNINDENT
  2052. .sp
  2053. Specifies a different port, or IP address and port, from the default of
  2054. \fB127.0.0.1:8000\fP\&. This value follows exactly the same format and serves
  2055. exactly the same function as the argument to the \fI\%runserver\fP command.
  2056. .sp
  2057. Examples:
  2058. .sp
  2059. To run the test server on port 7000 with \fBfixture1\fP and \fBfixture2\fP:
  2060. .INDENT 0.0
  2061. .INDENT 3.5
  2062. .sp
  2063. .EX
  2064. django\-admin testserver \-\-addrport 7000 fixture1 fixture2
  2065. django\-admin testserver fixture1 fixture2 \-\-addrport 7000
  2066. .EE
  2067. .UNINDENT
  2068. .UNINDENT
  2069. .sp
  2070. (The above statements are equivalent. We include both of them to demonstrate
  2071. that it doesn\(aqt matter whether the options come before or after the fixture
  2072. arguments.)
  2073. .sp
  2074. To run on 1.2.3.4:7000 with a \fBtest\fP fixture:
  2075. .INDENT 0.0
  2076. .INDENT 3.5
  2077. .sp
  2078. .EX
  2079. django\-admin testserver \-\-addrport 1.2.3.4:7000 test
  2080. .EE
  2081. .UNINDENT
  2082. .UNINDENT
  2083. .INDENT 0.0
  2084. .TP
  2085. .B \-\-noinput, \-\-no\-input
  2086. .UNINDENT
  2087. .sp
  2088. Suppresses all user prompts. A typical prompt is a warning about deleting an
  2089. existing test database.
  2090. .SH COMMANDS PROVIDED BY APPLICATIONS
  2091. .sp
  2092. Some commands are only available when the \fBdjango.contrib\fP application that
  2093. \fI\%implements\fP them has been
  2094. \X'tty: link #std-setting-INSTALLED_APPS'\fI\%enabled\fP\X'tty: link'\&. This section describes them grouped by
  2095. their application.
  2096. .SS \fBdjango.contrib.auth\fP
  2097. .SS \fBchangepassword\fP
  2098. .INDENT 0.0
  2099. .TP
  2100. .B django\-admin changepassword [<username>]
  2101. .UNINDENT
  2102. .sp
  2103. This command is only available if Django\(aqs \fI\%authentication system\fP (\fBdjango.contrib.auth\fP) is installed.
  2104. .sp
  2105. Allows changing a user\(aqs password. It prompts you to enter a new password twice
  2106. for the given user. If the entries are identical, this immediately becomes the
  2107. new password. If you do not supply a user, the command will attempt to change
  2108. the password whose username matches the current user.
  2109. .INDENT 0.0
  2110. .TP
  2111. .B \-\-database DATABASE
  2112. .UNINDENT
  2113. .sp
  2114. Specifies the database to query for the user. Defaults to \fBdefault\fP\&.
  2115. .sp
  2116. Example usage:
  2117. .INDENT 0.0
  2118. .INDENT 3.5
  2119. .sp
  2120. .EX
  2121. django\-admin changepassword ringo
  2122. .EE
  2123. .UNINDENT
  2124. .UNINDENT
  2125. .SS \fBcreatesuperuser\fP
  2126. .INDENT 0.0
  2127. .TP
  2128. .B django\-admin createsuperuser
  2129. .UNINDENT
  2130. .INDENT 0.0
  2131. .TP
  2132. .B DJANGO_SUPERUSER_PASSWORD
  2133. .UNINDENT
  2134. .sp
  2135. This command is only available if Django\(aqs \fI\%authentication system\fP (\fBdjango.contrib.auth\fP) is installed.
  2136. .sp
  2137. Creates a superuser account (a user who has all permissions). This is
  2138. useful if you need to create an initial superuser account or if you need to
  2139. programmatically generate superuser accounts for your site(s).
  2140. .sp
  2141. When run interactively, this command will prompt for a password for
  2142. the new superuser account. When run non\-interactively, you can provide
  2143. a password by setting the \fI\%DJANGO_SUPERUSER_PASSWORD\fP environment
  2144. variable. Otherwise, no password will be set, and the superuser account will
  2145. not be able to log in until a password has been manually set for it.
  2146. .sp
  2147. In non\-interactive mode, the
  2148. \X'tty: link #django.contrib.auth.models.CustomUser.USERNAME_FIELD'\fI\%USERNAME_FIELD\fP\X'tty: link' and required
  2149. fields (listed in
  2150. \X'tty: link #django.contrib.auth.models.CustomUser.REQUIRED_FIELDS'\fI\%REQUIRED_FIELDS\fP\X'tty: link') fall back to
  2151. \fBDJANGO_SUPERUSER_<uppercase_field_name>\fP environment variables, unless they
  2152. are overridden by a command line argument. For example, to provide an \fBemail\fP
  2153. field, you can use \fBDJANGO_SUPERUSER_EMAIL\fP environment variable.
  2154. .INDENT 0.0
  2155. .TP
  2156. .B \-\-noinput, \-\-no\-input
  2157. .UNINDENT
  2158. .sp
  2159. Suppresses all user prompts. If a suppressed prompt cannot be resolved
  2160. automatically, the command will exit with error code 1.
  2161. .INDENT 0.0
  2162. .TP
  2163. .B \-\-username USERNAME
  2164. .UNINDENT
  2165. .INDENT 0.0
  2166. .TP
  2167. .B \-\-email EMAIL
  2168. .UNINDENT
  2169. .sp
  2170. The username and email address for the new account can be supplied by
  2171. using the \fB\-\-username\fP and \fB\-\-email\fP arguments on the command
  2172. line. If either of those is not supplied, \fBcreatesuperuser\fP will prompt for
  2173. it when running interactively.
  2174. .INDENT 0.0
  2175. .TP
  2176. .B \-\-database DATABASE
  2177. .UNINDENT
  2178. .sp
  2179. Specifies the database into which the superuser object will be saved.
  2180. .sp
  2181. You can subclass the management command and override \fBget_input_data()\fP if you
  2182. want to customize data input and validation. Consult the source code for
  2183. details on the existing implementation and the method\(aqs parameters. For example,
  2184. it could be useful if you have a \fBForeignKey\fP in
  2185. \X'tty: link #django.contrib.auth.models.CustomUser.REQUIRED_FIELDS'\fI\%REQUIRED_FIELDS\fP\X'tty: link' and want to
  2186. allow creating an instance instead of entering the primary key of an existing
  2187. instance.
  2188. .SS \fBdjango.contrib.contenttypes\fP
  2189. .SS \fBremove_stale_contenttypes\fP
  2190. .INDENT 0.0
  2191. .TP
  2192. .B django\-admin remove_stale_contenttypes
  2193. .UNINDENT
  2194. .sp
  2195. This command is only available if Django\(aqs \fI\%contenttypes app\fP (\X'tty: link #module-django.contrib.contenttypes'\fI\%django.contrib.contenttypes\fP\X'tty: link') is installed.
  2196. .sp
  2197. Deletes stale content types (from deleted models) in your database. Any objects
  2198. that depend on the deleted content types will also be deleted. A list of
  2199. deleted objects will be displayed before you confirm it\(aqs okay to proceed with
  2200. the deletion.
  2201. .INDENT 0.0
  2202. .TP
  2203. .B \-\-database DATABASE
  2204. .UNINDENT
  2205. .sp
  2206. Specifies the database to use. Defaults to \fBdefault\fP\&.
  2207. .INDENT 0.0
  2208. .TP
  2209. .B \-\-include\-stale\-apps
  2210. .UNINDENT
  2211. .sp
  2212. Deletes stale content types including ones from previously installed apps that
  2213. have been removed from \X'tty: link #std-setting-INSTALLED_APPS'\fI\%INSTALLED_APPS\fP\X'tty: link'\&. Defaults to \fBFalse\fP\&.
  2214. .SS \fBdjango.contrib.gis\fP
  2215. .SS \fBogrinspect\fP
  2216. .sp
  2217. This command is only available if \fI\%GeoDjango\fP
  2218. (\fBdjango.contrib.gis\fP) is installed.
  2219. .sp
  2220. Please refer to its \X'tty: link #django-admin-ogrinspect'\fI\%description\fP\X'tty: link' in the GeoDjango
  2221. documentation.
  2222. .SS \fBdjango.contrib.sessions\fP
  2223. .SS \fBclearsessions\fP
  2224. .INDENT 0.0
  2225. .TP
  2226. .B django\-admin clearsessions
  2227. .UNINDENT
  2228. .sp
  2229. Can be run as a cron job or directly to clean out expired sessions.
  2230. .SS \fBdjango.contrib.staticfiles\fP
  2231. .SS \fBcollectstatic\fP
  2232. .sp
  2233. This command is only available if the \fI\%static files application\fP (\fBdjango.contrib.staticfiles\fP) is installed.
  2234. .sp
  2235. Please refer to its \X'tty: link #django-admin-collectstatic'\fI\%description\fP\X'tty: link' in the
  2236. \fI\%staticfiles\fP documentation.
  2237. .SS \fBfindstatic\fP
  2238. .sp
  2239. This command is only available if the \fI\%static files application\fP (\fBdjango.contrib.staticfiles\fP) is installed.
  2240. .sp
  2241. Please refer to its \X'tty: link #django-admin-findstatic'\fI\%description\fP\X'tty: link' in the \fI\%staticfiles\fP documentation.
  2242. .SH DEFAULT OPTIONS
  2243. .sp
  2244. Although some commands may allow their own custom options, every command
  2245. allows for the following options by default:
  2246. .INDENT 0.0
  2247. .TP
  2248. .B \-\-pythonpath PYTHONPATH
  2249. .UNINDENT
  2250. .sp
  2251. Adds the given filesystem path to the Python \X'tty: link https://docs.python.org/3/library/sys.html#sys.path'\fI\%sys.path\fP\X'tty: link' module
  2252. attribute. If this isn\(aqt provided, \fBdjango\-admin\fP will use the
  2253. \X'tty: link https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH'\fI\%PYTHONPATH\fP\X'tty: link' environment variable.
  2254. .sp
  2255. This option is unnecessary in \fBmanage.py\fP, because it takes care of setting
  2256. the Python path for you.
  2257. .sp
  2258. Example usage:
  2259. .INDENT 0.0
  2260. .INDENT 3.5
  2261. .sp
  2262. .EX
  2263. django\-admin migrate \-\-pythonpath=\(aq/home/djangoprojects/myproject\(aq
  2264. .EE
  2265. .UNINDENT
  2266. .UNINDENT
  2267. .INDENT 0.0
  2268. .TP
  2269. .B \-\-settings SETTINGS
  2270. .UNINDENT
  2271. .sp
  2272. Specifies the settings module to use. The settings module should be in Python
  2273. package syntax, e.g. \fBmysite.settings\fP\&. If this isn\(aqt provided,
  2274. \fBdjango\-admin\fP will use the \X'tty: link #envvar-DJANGO_SETTINGS_MODULE'\fI\%DJANGO_SETTINGS_MODULE\fP\X'tty: link' environment
  2275. variable.
  2276. .sp
  2277. This option is unnecessary in \fBmanage.py\fP, because it uses
  2278. \fBsettings.py\fP from the current project by default.
  2279. .sp
  2280. Example usage:
  2281. .INDENT 0.0
  2282. .INDENT 3.5
  2283. .sp
  2284. .EX
  2285. django\-admin migrate \-\-settings=mysite.settings
  2286. .EE
  2287. .UNINDENT
  2288. .UNINDENT
  2289. .INDENT 0.0
  2290. .TP
  2291. .B \-\-traceback
  2292. .UNINDENT
  2293. .sp
  2294. Displays a full stack trace when a \X'tty: link #django.core.management.CommandError'\fI\%CommandError\fP\X'tty: link'
  2295. is raised. By default, \fBdjango\-admin\fP will show an error message when a
  2296. \fBCommandError\fP occurs and a full stack trace for any other exception.
  2297. .sp
  2298. This option is ignored by \fI\%runserver\fP\&.
  2299. .sp
  2300. Example usage:
  2301. .INDENT 0.0
  2302. .INDENT 3.5
  2303. .sp
  2304. .EX
  2305. django\-admin migrate \-\-traceback
  2306. .EE
  2307. .UNINDENT
  2308. .UNINDENT
  2309. .INDENT 0.0
  2310. .TP
  2311. .B \-\-verbosity {0,1,2,3}, \-v {0,1,2,3}
  2312. .UNINDENT
  2313. .sp
  2314. Specifies the amount of notification and debug information that a command
  2315. should print to the console.
  2316. .INDENT 0.0
  2317. .IP \(bu 2
  2318. \fB0\fP means no output.
  2319. .IP \(bu 2
  2320. \fB1\fP means normal output (default).
  2321. .IP \(bu 2
  2322. \fB2\fP means verbose output.
  2323. .IP \(bu 2
  2324. \fB3\fP means \fIvery\fP verbose output.
  2325. .UNINDENT
  2326. .sp
  2327. This option is ignored by \fI\%runserver\fP\&.
  2328. .sp
  2329. Example usage:
  2330. .INDENT 0.0
  2331. .INDENT 3.5
  2332. .sp
  2333. .EX
  2334. django\-admin migrate \-\-verbosity 2
  2335. .EE
  2336. .UNINDENT
  2337. .UNINDENT
  2338. .INDENT 0.0
  2339. .TP
  2340. .B \-\-no\-color
  2341. .UNINDENT
  2342. .sp
  2343. Disables colorized command output. Some commands format their output to be
  2344. colorized. For example, errors will be printed to the console in red and SQL
  2345. statements will be syntax highlighted.
  2346. .sp
  2347. Example usage:
  2348. .INDENT 0.0
  2349. .INDENT 3.5
  2350. .sp
  2351. .EX
  2352. django\-admin runserver \-\-no\-color
  2353. .EE
  2354. .UNINDENT
  2355. .UNINDENT
  2356. .INDENT 0.0
  2357. .TP
  2358. .B \-\-force\-color
  2359. .UNINDENT
  2360. .sp
  2361. Forces colorization of the command output if it would otherwise be disabled
  2362. as discussed in \fI\%Syntax coloring\fP\&. For example, you may want to pipe
  2363. colored output to another command.
  2364. .INDENT 0.0
  2365. .TP
  2366. .B \-\-skip\-checks
  2367. .UNINDENT
  2368. .sp
  2369. Skips running system checks prior to running the command. This option is only
  2370. available if the
  2371. \X'tty: link #django.core.management.BaseCommand.requires_system_checks'\fI\%requires_system_checks\fP\X'tty: link' command
  2372. attribute is not an empty list or tuple.
  2373. .sp
  2374. Example usage:
  2375. .INDENT 0.0
  2376. .INDENT 3.5
  2377. .sp
  2378. .EX
  2379. django\-admin migrate \-\-skip\-checks
  2380. .EE
  2381. .UNINDENT
  2382. .UNINDENT
  2383. .SH EXTRA NICETIES
  2384. .SS Syntax coloring
  2385. .INDENT 0.0
  2386. .TP
  2387. .B DJANGO_COLORS
  2388. .UNINDENT
  2389. .sp
  2390. The \fBdjango\-admin\fP / \fBmanage.py\fP commands will use pretty
  2391. color\-coded output if your terminal supports ANSI\-colored output. It
  2392. won\(aqt use the color codes if you\(aqre piping the command\(aqs output to
  2393. another program unless the \fI\%\-\-force\-color\fP option is used.
  2394. .SS Windows support
  2395. .sp
  2396. On Windows 10, the \X'tty: link https://www.microsoft.com/en-us/p/windows-terminal-preview/9n0dx20hk701'\fI\%Windows Terminal\fP\X'tty: link' application, \X'tty: link https://code.visualstudio.com'\fI\%VS Code\fP\X'tty: link', and PowerShell
  2397. (where virtual terminal processing is enabled) allow colored output, and are
  2398. supported by default.
  2399. .sp
  2400. Under Windows, the legacy \fBcmd.exe\fP native console doesn\(aqt support ANSI
  2401. escape sequences so by default there is no color output. In this case either of
  2402. two third\-party libraries are needed:
  2403. .INDENT 0.0
  2404. .IP \(bu 2
  2405. Install \X'tty: link https://pypi.org/project/colorama/'\fI\%colorama\fP\X'tty: link', a Python package that translates ANSI color codes
  2406. into Windows API calls. Django commands will detect its presence and will
  2407. make use of its services to color output just like on Unix\-based platforms.
  2408. \fBcolorama\fP can be installed via pip:
  2409. .INDENT 2.0
  2410. .INDENT 3.5
  2411. .sp
  2412. .EX
  2413. \&...\e> py \-m pip install \(dqcolorama >= 0.4.6\(dq
  2414. .EE
  2415. .UNINDENT
  2416. .UNINDENT
  2417. .IP \(bu 2
  2418. Install \X'tty: link http://adoxa.altervista.org/ansicon/'\fI\%ANSICON\fP\X'tty: link', a third\-party tool that allows \fBcmd.exe\fP to process
  2419. ANSI color codes. Django commands will detect its presence and will make use
  2420. of its services to color output just like on Unix\-based platforms.
  2421. .UNINDENT
  2422. .sp
  2423. Other modern terminal environments on Windows, that support terminal colors,
  2424. but which are not automatically detected as supported by Django, may \(dqfake\(dq the
  2425. installation of \fBANSICON\fP by setting the appropriate environmental variable,
  2426. \fBANSICON=\(dqon\(dq\fP\&.
  2427. .SS Custom colors
  2428. .sp
  2429. The colors used for syntax highlighting can be customized. Django
  2430. ships with three color palettes:
  2431. .INDENT 0.0
  2432. .IP \(bu 2
  2433. \fBdark\fP, suited to terminals that show white text on a black
  2434. background. This is the default palette.
  2435. .IP \(bu 2
  2436. \fBlight\fP, suited to terminals that show black text on a white
  2437. background.
  2438. .IP \(bu 2
  2439. \fBnocolor\fP, which disables syntax highlighting.
  2440. .UNINDENT
  2441. .sp
  2442. You select a palette by setting a \fI\%DJANGO_COLORS\fP environment
  2443. variable to specify the palette you want to use. For example, to
  2444. specify the \fBlight\fP palette under a Unix or OS/X BASH shell, you
  2445. would run the following at a command prompt:
  2446. .INDENT 0.0
  2447. .INDENT 3.5
  2448. .sp
  2449. .EX
  2450. export DJANGO_COLORS=\(dqlight\(dq
  2451. .EE
  2452. .UNINDENT
  2453. .UNINDENT
  2454. .sp
  2455. You can also customize the colors that are used. Django specifies a
  2456. number of roles in which color is used:
  2457. .INDENT 0.0
  2458. .IP \(bu 2
  2459. \fBerror\fP \- A major error.
  2460. .IP \(bu 2
  2461. \fBnotice\fP \- A minor error.
  2462. .IP \(bu 2
  2463. \fBsuccess\fP \- A success.
  2464. .IP \(bu 2
  2465. \fBwarning\fP \- A warning.
  2466. .IP \(bu 2
  2467. \fBsql_field\fP \- The name of a model field in SQL.
  2468. .IP \(bu 2
  2469. \fBsql_coltype\fP \- The type of a model field in SQL.
  2470. .IP \(bu 2
  2471. \fBsql_keyword\fP \- An SQL keyword.
  2472. .IP \(bu 2
  2473. \fBsql_table\fP \- The name of a model in SQL.
  2474. .IP \(bu 2
  2475. \fBhttp_info\fP \- A 1XX HTTP Informational server response.
  2476. .IP \(bu 2
  2477. \fBhttp_success\fP \- A 2XX HTTP Success server response.
  2478. .IP \(bu 2
  2479. \fBhttp_not_modified\fP \- A 304 HTTP Not Modified server response.
  2480. .IP \(bu 2
  2481. \fBhttp_redirect\fP \- A 3XX HTTP Redirect server response other than 304.
  2482. .IP \(bu 2
  2483. \fBhttp_not_found\fP \- A 404 HTTP Not Found server response.
  2484. .IP \(bu 2
  2485. \fBhttp_bad_request\fP \- A 4XX HTTP Bad Request server response other than 404.
  2486. .IP \(bu 2
  2487. \fBhttp_server_error\fP \- A 5XX HTTP Server Error response.
  2488. .IP \(bu 2
  2489. \fBmigrate_heading\fP \- A heading in a migrations management command.
  2490. .IP \(bu 2
  2491. \fBmigrate_label\fP \- A migration name.
  2492. .UNINDENT
  2493. .sp
  2494. Each of these roles can be assigned a specific foreground and
  2495. background color, from the following list:
  2496. .INDENT 0.0
  2497. .IP \(bu 2
  2498. \fBblack\fP
  2499. .IP \(bu 2
  2500. \fBred\fP
  2501. .IP \(bu 2
  2502. \fBgreen\fP
  2503. .IP \(bu 2
  2504. \fByellow\fP
  2505. .IP \(bu 2
  2506. \fBblue\fP
  2507. .IP \(bu 2
  2508. \fBmagenta\fP
  2509. .IP \(bu 2
  2510. \fBcyan\fP
  2511. .IP \(bu 2
  2512. \fBwhite\fP
  2513. .UNINDENT
  2514. .sp
  2515. Each of these colors can then be modified by using the following
  2516. display options:
  2517. .INDENT 0.0
  2518. .IP \(bu 2
  2519. \fBbold\fP
  2520. .IP \(bu 2
  2521. \fBunderscore\fP
  2522. .IP \(bu 2
  2523. \fBblink\fP
  2524. .IP \(bu 2
  2525. \fBreverse\fP
  2526. .IP \(bu 2
  2527. \fBconceal\fP
  2528. .UNINDENT
  2529. .sp
  2530. A color specification follows one of the following patterns:
  2531. .INDENT 0.0
  2532. .IP \(bu 2
  2533. \fBrole=fg\fP
  2534. .IP \(bu 2
  2535. \fBrole=fg/bg\fP
  2536. .IP \(bu 2
  2537. \fBrole=fg,option,option\fP
  2538. .IP \(bu 2
  2539. \fBrole=fg/bg,option,option\fP
  2540. .UNINDENT
  2541. .sp
  2542. where \fBrole\fP is the name of a valid color role, \fBfg\fP is the
  2543. foreground color, \fBbg\fP is the background color and each \fBoption\fP
  2544. is one of the color modifying options. Multiple color specifications
  2545. are then separated by a semicolon. For example:
  2546. .INDENT 0.0
  2547. .INDENT 3.5
  2548. .sp
  2549. .EX
  2550. export DJANGO_COLORS=\(dqerror=yellow/blue,blink;notice=magenta\(dq
  2551. .EE
  2552. .UNINDENT
  2553. .UNINDENT
  2554. .sp
  2555. would specify that errors be displayed using blinking yellow on blue,
  2556. and notices displayed using magenta. All other color roles would be
  2557. left uncolored.
  2558. .sp
  2559. Colors can also be specified by extending a base palette. If you put
  2560. a palette name in a color specification, all the colors implied by that
  2561. palette will be loaded. So:
  2562. .INDENT 0.0
  2563. .INDENT 3.5
  2564. .sp
  2565. .EX
  2566. export DJANGO_COLORS=\(dqlight;error=yellow/blue,blink;notice=magenta\(dq
  2567. .EE
  2568. .UNINDENT
  2569. .UNINDENT
  2570. .sp
  2571. would specify the use of all the colors in the light color palette,
  2572. \fIexcept\fP for the colors for errors and notices which would be
  2573. overridden as specified.
  2574. .SS Bash completion
  2575. .sp
  2576. If you use the Bash shell, consider installing the Django bash completion
  2577. script, which lives in \X'tty: link https://github.com/django/django/blob/main/extras/django_bash_completion'\fI\%extras/django_bash_completion\fP\X'tty: link' in the Django source
  2578. distribution. It enables tab\-completion of \fBdjango\-admin\fP and
  2579. \fBmanage.py\fP commands, so you can, for instance...
  2580. .INDENT 0.0
  2581. .IP \(bu 2
  2582. Type \fBdjango\-admin\fP\&.
  2583. .IP \(bu 2
  2584. Press [TAB] to see all available options.
  2585. .IP \(bu 2
  2586. Type \fBsql\fP, then [TAB], to see all available options whose names start
  2587. with \fBsql\fP\&.
  2588. .UNINDENT
  2589. .sp
  2590. See \fI\%How to create custom django\-admin commands\fP for how to add customized actions.
  2591. .SS Black formatting
  2592. .sp
  2593. The Python files created by \fI\%startproject\fP, \fI\%startapp\fP,
  2594. \fI\%optimizemigration\fP, \fI\%makemigrations\fP, and
  2595. \fI\%squashmigrations\fP are formatted using the \fBblack\fP command if it is
  2596. present on your \fBPATH\fP\&.
  2597. .sp
  2598. If you have \fBblack\fP globally installed, but do not wish it used for the
  2599. current project, you can set the \fBPATH\fP explicitly:
  2600. .INDENT 0.0
  2601. .INDENT 3.5
  2602. .sp
  2603. .EX
  2604. PATH=path/to/venv/bin django\-admin makemigrations
  2605. .EE
  2606. .UNINDENT
  2607. .UNINDENT
  2608. .sp
  2609. For commands using \fBstdout\fP you can pipe the output to \fBblack\fP if needed:
  2610. .INDENT 0.0
  2611. .INDENT 3.5
  2612. .sp
  2613. .EX
  2614. django\-admin inspectdb | black \-
  2615. .EE
  2616. .UNINDENT
  2617. .UNINDENT
  2618. .INDENT 0.0
  2619. .TP
  2620. .B django.core.management.call_command(name, *args, **options)
  2621. .UNINDENT
  2622. .sp
  2623. To call a management command from code use \fBcall_command()\fP\&.
  2624. .INDENT 0.0
  2625. .TP
  2626. .B \fBname\fP
  2627. the name of the command to call or a command object. Passing the name is
  2628. preferred unless the object is required for testing.
  2629. .TP
  2630. .B \fB*args\fP
  2631. a list of arguments accepted by the command. Arguments are passed to the
  2632. argument parser, so you can use the same style as you would on the command
  2633. line. For example, \fBcall_command(\(aqflush\(aq, \(aq\-\-verbosity=0\(aq)\fP\&.
  2634. .TP
  2635. .B \fB**options\fP
  2636. named options accepted on the command\-line. Options are passed to the command
  2637. without triggering the argument parser, which means you\(aqll need to pass the
  2638. correct type. For example, \fBcall_command(\(aqflush\(aq, verbosity=0)\fP (zero must
  2639. be an integer rather than a string).
  2640. .UNINDENT
  2641. .sp
  2642. Examples:
  2643. .INDENT 0.0
  2644. .INDENT 3.5
  2645. .sp
  2646. .EX
  2647. from django.core import management
  2648. from django.core.management.commands import loaddata
  2649. management.call_command(\(dqflush\(dq, verbosity=0, interactive=False)
  2650. management.call_command(\(dqloaddata\(dq, \(dqtest_data\(dq, verbosity=0)
  2651. management.call_command(loaddata.Command(), \(dqtest_data\(dq, verbosity=0)
  2652. .EE
  2653. .UNINDENT
  2654. .UNINDENT
  2655. .sp
  2656. Note that command options that take no arguments are passed as keywords
  2657. with \fBTrue\fP or \fBFalse\fP, as you can see with the \fBinteractive\fP option above.
  2658. .sp
  2659. Named arguments can be passed by using either one of the following syntaxes:
  2660. .INDENT 0.0
  2661. .INDENT 3.5
  2662. .sp
  2663. .EX
  2664. # Similar to the command line
  2665. management.call_command(\(dqdumpdata\(dq, \(dq\-\-natural\-foreign\(dq)
  2666. # Named argument similar to the command line minus the initial dashes and
  2667. # with internal dashes replaced by underscores
  2668. management.call_command(\(dqdumpdata\(dq, natural_foreign=True)
  2669. # \(gause_natural_foreign_keys\(ga is the option destination variable
  2670. management.call_command(\(dqdumpdata\(dq, use_natural_foreign_keys=True)
  2671. .EE
  2672. .UNINDENT
  2673. .UNINDENT
  2674. .sp
  2675. Some command options have different names when using \fBcall_command()\fP instead
  2676. of \fBdjango\-admin\fP or \fBmanage.py\fP\&. For example, \fBdjango\-admin
  2677. createsuperuser \-\-no\-input\fP translates to \fBcall_command(\(aqcreatesuperuser\(aq,
  2678. interactive=False)\fP\&. To find what keyword argument name to use for
  2679. \fBcall_command()\fP, check the command\(aqs source code for the \fBdest\fP argument
  2680. passed to \fBparser.add_argument()\fP\&.
  2681. .sp
  2682. Command options which take multiple options are passed a list:
  2683. .INDENT 0.0
  2684. .INDENT 3.5
  2685. .sp
  2686. .EX
  2687. management.call_command(\(dqdumpdata\(dq, exclude=[\(dqcontenttypes\(dq, \(dqauth\(dq])
  2688. .EE
  2689. .UNINDENT
  2690. .UNINDENT
  2691. .sp
  2692. The return value of the \fBcall_command()\fP function is the same as the return
  2693. value of the \fBhandle()\fP method of the command.
  2694. .SH OUTPUT REDIRECTION
  2695. .sp
  2696. Note that you can redirect standard output and error streams as all commands
  2697. support the \fBstdout\fP and \fBstderr\fP options. For example, you could write:
  2698. .INDENT 0.0
  2699. .INDENT 3.5
  2700. .sp
  2701. .EX
  2702. with open(\(dq/path/to/command_output\(dq, \(dqw\(dq) as f:
  2703. management.call_command(\(dqdumpdata\(dq, stdout=f)
  2704. .EE
  2705. .UNINDENT
  2706. .UNINDENT
  2707. .SH AUTHOR
  2708. Django Software Foundation
  2709. .SH COPYRIGHT
  2710. Django Software Foundation and contributors
  2711. .\" Generated by docutils manpage writer.
  2712. .