django-admin.txt 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. .. _ref-django-admin:
  2. =============================
  3. django-admin.py and manage.py
  4. =============================
  5. ``django-admin.py`` is Django's command-line utility for administrative tasks.
  6. This document outlines all it can do.
  7. In addition, ``manage.py`` is automatically created in each Django project.
  8. ``manage.py`` is a thin wrapper around ``django-admin.py`` that takes care of
  9. two things for you before delegating to ``django-admin.py``:
  10. * It puts your project's package on ``sys.path``.
  11. * It sets the :envvar:`DJANGO_SETTINGS_MODULE` environment variable so that
  12. it points to your project's ``settings.py`` file.
  13. The ``django-admin.py`` script should be on your system path if you installed
  14. Django via its ``setup.py`` utility. If it's not on your path, you can find it
  15. in ``site-packages/django/bin`` within your Python installation. Consider
  16. symlinking it from some place on your path, such as ``/usr/local/bin``.
  17. For Windows users, who do not have symlinking functionality available, you can
  18. copy ``django-admin.py`` to a location on your existing path or edit the
  19. ``PATH`` settings (under ``Settings - Control Panel - System - Advanced -
  20. Environment...``) to point to its installed location.
  21. Generally, when working on a single Django project, it's easier to use
  22. ``manage.py``. Use ``django-admin.py`` with ``DJANGO_SETTINGS_MODULE``, or the
  23. ``--settings`` command line option, if you need to switch between multiple
  24. Django settings files.
  25. The command-line examples throughout this document use ``django-admin.py`` to
  26. be consistent, but any example can use ``manage.py`` just as well.
  27. Usage
  28. =====
  29. .. code-block:: bash
  30. django-admin.py <subcommand> [options]
  31. manage.py <subcommand> [options]
  32. ``subcommand`` should be one of the subcommands listed in this document.
  33. ``options``, which is optional, should be zero or more of the options available
  34. for the given subcommand.
  35. Getting runtime help
  36. --------------------
  37. .. django-admin-option:: --help
  38. Run ``django-admin.py help`` to display a list of all available subcommands.
  39. Run ``django-admin.py help <subcommand>`` to display a description of the
  40. given subcommand and a list of its available options.
  41. App names
  42. ---------
  43. Many subcommands take a list of "app names." An "app name" is the basename of
  44. the package containing your models. For example, if your ``INSTALLED_APPS``
  45. contains the string ``'mysite.blog'``, the app name is ``blog``.
  46. Determining the version
  47. -----------------------
  48. .. django-admin-option:: --version
  49. Run ``django-admin.py --version`` to display the current Django version.
  50. Examples of output::
  51. 0.95
  52. 0.96
  53. 0.97-pre-SVN-6069
  54. Displaying debug output
  55. -----------------------
  56. Use :djadminopt:`--verbosity` to specify the amount of notification and debug information
  57. that ``django-admin.py`` should print to the console. For more details, see the
  58. documentation for the :djadminopt:`--verbosity` option.
  59. Available subcommands
  60. =====================
  61. cleanup
  62. -------
  63. .. django-admin:: cleanup
  64. .. versionadded:: 1.0
  65. Can be run as a cronjob or directly to clean out old data from the database
  66. (only expired sessions at the moment).
  67. compilemessages
  68. ---------------
  69. .. django-admin:: compilemessages
  70. .. versionchanged:: 1.0
  71. Before 1.0 this was the "bin/compile-messages.py" command.
  72. Compiles .po files created with ``makemessages`` to .mo files for use with
  73. the builtin gettext support. See :ref:`topics-i18n`.
  74. Use the :djadminopt:`--locale`` option to specify the locale to process.
  75. If not provided, all locales are processed.
  76. Example usage::
  77. django-admin.py compilemessages --locale=br_PT
  78. createcachetable
  79. ----------------
  80. .. django-admin:: createcachetable
  81. Creates a cache table named ``tablename`` for use with the database cache
  82. backend. See :ref:`topics-cache` for more information.
  83. createsuperuser
  84. ---------------
  85. .. django-admin:: createsuperuser
  86. .. versionadded:: 1.0
  87. Creates a superuser account (a user who has all permissions). This is
  88. useful if you need to create an initial superuser account but did not
  89. do so during ``syncdb``, or if you need to programmatically generate
  90. superuser accounts for your site(s).
  91. When run interactively, this command will prompt for a password for
  92. the new superuser account. When run non-interactively, no password
  93. will be set, and the superuser account will not be able to log in until
  94. a password has been manually set for it.
  95. .. django-admin-option:: --username
  96. .. django-admin-option:: --email
  97. The username and e-mail address for the new account can be supplied by
  98. using the ``--username`` and ``--email`` arguments on the command
  99. line. If either of those is not supplied, ``createsuperuser`` will prompt for
  100. it when running interactively.
  101. This command is only available if Django's :ref:`authentication system
  102. <topics-auth>` (``django.contrib.auth``) is installed.
  103. dbshell
  104. -------
  105. .. django-admin:: dbshell
  106. Runs the command-line client for the database engine specified in your
  107. ``DATABASE_ENGINE`` setting, with the connection parameters specified in your
  108. ``DATABASE_USER``, ``DATABASE_PASSWORD``, etc., settings.
  109. * For PostgreSQL, this runs the ``psql`` command-line client.
  110. * For MySQL, this runs the ``mysql`` command-line client.
  111. * For SQLite, this runs the ``sqlite3`` command-line client.
  112. This command assumes the programs are on your ``PATH`` so that a simple call to
  113. the program name (``psql``, ``mysql``, ``sqlite3``) will find the program in
  114. the right place. There's no way to specify the location of the program
  115. manually.
  116. diffsettings
  117. ------------
  118. .. django-admin:: diffsettings
  119. Displays differences between the current settings file and Django's default
  120. settings.
  121. Settings that don't appear in the defaults are followed by ``"###"``. For
  122. example, the default settings don't define ``ROOT_URLCONF``, so
  123. ``ROOT_URLCONF`` is followed by ``"###"`` in the output of ``diffsettings``.
  124. Note that Django's default settings live in ``django/conf/global_settings.py``,
  125. if you're ever curious to see the full list of defaults.
  126. dumpdata <appname appname appname.Model ...>
  127. --------------------------------------------
  128. .. django-admin:: dumpdata
  129. Outputs to standard output all data in the database associated with the named
  130. application(s).
  131. If no application name is provided, all installed applications will be dumped.
  132. The output of ``dumpdata`` can be used as input for ``loaddata``.
  133. Note that ``dumpdata`` uses the default manager on the model for selecting the
  134. records to dump. If you're using a :ref:`custom manager <custom-managers>` as
  135. the default manager and it filters some of the available records, not all of the
  136. objects will be dumped.
  137. .. django-admin-option:: --exclude
  138. .. versionadded:: 1.0
  139. Exclude a specific application from the applications whose contents is
  140. output. For example, to specifically exclude the `auth` application from
  141. the output, you would call::
  142. django-admin.py dumpdata --exclude=auth
  143. If you want to exclude multiple applications, use multiple ``--exclude``
  144. directives::
  145. django-admin.py dumpdata --exclude=auth --exclude=contenttypes
  146. .. django-admin-option:: --format <fmt>
  147. By default, ``dumpdata`` will format its output in JSON, but you can use the
  148. ``--format`` option to specify another format. Currently supported formats
  149. are listed in :ref:`serialization-formats`.
  150. .. django-admin-option:: --indent <num>
  151. By default, ``dumpdata`` will output all data on a single line. This isn't
  152. easy for humans to read, so you can use the ``--indent`` option to
  153. pretty-print the output with a number of indentation spaces.
  154. .. versionadded:: 1.1
  155. In addition to specifying application names, you can provide a list of
  156. individual models, in the form of ``appname.Model``. If you specify a model
  157. name to ``dumpdata``, the dumped output will be restricted to that model,
  158. rather than the entire application. You can also mix application names and
  159. model names.
  160. .. django-admin-option:: --natural
  161. .. versionadded:: 1.2
  162. Use :ref:`natural keys <topics-serialization-natural-keys>` to represent
  163. any foreign key and many-to-many relationship with a model that provides
  164. a natural key definition. If you are dumping ``contrib.auth`` ``Permission``
  165. objects or ``contrib.contenttypes`` ``ContentType`` objects, you should
  166. probably be using this flag.
  167. flush
  168. -----
  169. .. django-admin:: flush
  170. Returns the database to the state it was in immediately after syncdb was
  171. executed. This means that all data will be removed from the database, any
  172. post-synchronization handlers will be re-executed, and the ``initial_data``
  173. fixture will be re-installed.
  174. The :djadminopt:`--noinput` option may be provided to suppress all user
  175. prompts.
  176. inspectdb
  177. ---------
  178. .. django-admin:: inspectdb
  179. Introspects the database tables in the database pointed-to by the
  180. ``DATABASE_NAME`` setting and outputs a Django model module (a ``models.py``
  181. file) to standard output.
  182. Use this if you have a legacy database with which you'd like to use Django.
  183. The script will inspect the database and create a model for each table within
  184. it.
  185. As you might expect, the created models will have an attribute for every field
  186. in the table. Note that ``inspectdb`` has a few special cases in its field-name
  187. output:
  188. * If ``inspectdb`` cannot map a column's type to a model field type, it'll
  189. use ``TextField`` and will insert the Python comment
  190. ``'This field type is a guess.'`` next to the field in the generated
  191. model.
  192. * If the database column name is a Python reserved word (such as
  193. ``'pass'``, ``'class'`` or ``'for'``), ``inspectdb`` will append
  194. ``'_field'`` to the attribute name. For example, if a table has a column
  195. ``'for'``, the generated model will have a field ``'for_field'``, with
  196. the ``db_column`` attribute set to ``'for'``. ``inspectdb`` will insert
  197. the Python comment
  198. ``'Field renamed because it was a Python reserved word.'`` next to the
  199. field.
  200. This feature is meant as a shortcut, not as definitive model generation. After
  201. you run it, you'll want to look over the generated models yourself to make
  202. customizations. In particular, you'll need to rearrange models' order, so that
  203. models that refer to other models are ordered properly.
  204. Primary keys are automatically introspected for PostgreSQL, MySQL and
  205. SQLite, in which case Django puts in the ``primary_key=True`` where
  206. needed.
  207. ``inspectdb`` works with PostgreSQL, MySQL and SQLite. Foreign-key detection
  208. only works in PostgreSQL and with certain types of MySQL tables.
  209. loaddata <fixture fixture ...>
  210. ------------------------------
  211. .. django-admin:: loaddata
  212. Searches for and loads the contents of the named fixture into the database.
  213. What's a "fixture"?
  214. ~~~~~~~~~~~~~~~~~~~
  215. A *fixture* is a collection of files that contain the serialized contents of
  216. the database. Each fixture has a unique name, and the files that comprise the
  217. fixture can be distributed over multiple directories, in multiple applications.
  218. Django will search in three locations for fixtures:
  219. 1. In the ``fixtures`` directory of every installed application
  220. 2. In any directory named in the ``FIXTURE_DIRS`` setting
  221. 3. In the literal path named by the fixture
  222. Django will load any and all fixtures it finds in these locations that match
  223. the provided fixture names.
  224. If the named fixture has a file extension, only fixtures of that type
  225. will be loaded. For example::
  226. django-admin.py loaddata mydata.json
  227. would only load JSON fixtures called ``mydata``. The fixture extension
  228. must correspond to the registered name of a
  229. :ref:`serializer <serialization-formats>` (e.g., ``json`` or ``xml``).
  230. If you omit the extensions, Django will search all available fixture types
  231. for a matching fixture. For example::
  232. django-admin.py loaddata mydata
  233. would look for any fixture of any fixture type called ``mydata``. If a fixture
  234. directory contained ``mydata.json``, that fixture would be loaded
  235. as a JSON fixture.
  236. The fixtures that are named can include directory components. These
  237. directories will be included in the search path. For example::
  238. django-admin.py loaddata foo/bar/mydata.json
  239. would search ``<appname>/fixtures/foo/bar/mydata.json`` for each installed
  240. application, ``<dirname>/foo/bar/mydata.json`` for each directory in
  241. ``FIXTURE_DIRS``, and the literal path ``foo/bar/mydata.json``.
  242. When fixture files are processed, the data is saved to the database as is.
  243. Model defined ``save`` methods and ``pre_save`` signals are not called.
  244. Note that the order in which fixture files are processed is undefined. However,
  245. all fixture data is installed as a single transaction, so data in
  246. one fixture can reference data in another fixture. If the database backend
  247. supports row-level constraints, these constraints will be checked at the
  248. end of the transaction.
  249. The ``dumpdata`` command can be used to generate input for ``loaddata``.
  250. Compressed fixtures
  251. ~~~~~~~~~~~~~~~~~~~
  252. Fixtures may be compressed in ``zip``, ``gz``, or ``bz2`` format. For example::
  253. django-admin.py loaddata mydata.json
  254. would look for any of ``mydata.json``, ``mydata.json.zip``,
  255. ``mydata.json.gz``, or ``mydata.json.bz2``. The first file contained within a
  256. zip-compressed archive is used.
  257. Note that if two fixtures with the same name but different
  258. fixture type are discovered (for example, if ``mydata.json`` and
  259. ``mydata.xml.gz`` were found in the same fixture directory), fixture
  260. installation will be aborted, and any data installed in the call to
  261. ``loaddata`` will be removed from the database.
  262. .. admonition:: MySQL and Fixtures
  263. Unfortunately, MySQL isn't capable of completely supporting all the
  264. features of Django fixtures. If you use MyISAM tables, MySQL doesn't
  265. support transactions or constraints, so you won't get a rollback if
  266. multiple transaction files are found, or validation of fixture data.
  267. If you use InnoDB tables, you won't be able to have any forward
  268. references in your data files - MySQL doesn't provide a mechanism to
  269. defer checking of row constraints until a transaction is committed.
  270. makemessages
  271. ------------
  272. .. django-admin:: makemessages
  273. .. versionchanged:: 1.0
  274. Before 1.0 this was the ``bin/make-messages.py`` command.
  275. Runs over the entire source tree of the current directory and pulls out all
  276. strings marked for translation. It creates (or updates) a message file in the
  277. conf/locale (in the django tree) or locale (for project and application)
  278. directory. After making changes to the messages files you need to compile them
  279. with ``compilemessages`` for use with the builtin gettext support. See the
  280. :ref:`i18n documentation <how-to-create-language-files>` for details.
  281. .. django-admin-option:: --all
  282. Use the ``--all`` or ``-a`` option to update the message files for all
  283. available languages.
  284. Example usage::
  285. django-admin.py makemessages --all
  286. .. django-admin-option:: --extension
  287. Use the ``--extension`` or ``-e`` option to specify a list of file extensions
  288. to examine (default: ".html").
  289. Example usage::
  290. django-admin.py makemessages --locale=de --extension xhtml
  291. Separate multiple extensions with commas or use -e or --extension multiple times::
  292. django-admin.py makemessages --locale=de --extension=html,txt --extension xml
  293. Use the :djadminopt:`--locale` option to specify the locale to process.
  294. Example usage::
  295. django-admin.py makemessages --locale=br_PT
  296. .. django-admin-option:: --domain
  297. Use the ``--domain`` or ``-d`` option to change the domain of the messages files.
  298. Currently supported:
  299. * ``django`` for all ``*.py`` and ``*.html`` files (default)
  300. * ``djangojs`` for ``*.js`` files
  301. reset <appname appname ...>
  302. ---------------------------
  303. .. django-admin:: reset
  304. Executes the equivalent of ``sqlreset`` for the given app name(s).
  305. The :djadminopt:`--noinput` option may be provided to suppress all user
  306. prompts.
  307. runfcgi [options]
  308. -----------------
  309. .. django-admin:: runfcgi
  310. Starts a set of FastCGI processes suitable for use with any Web server that
  311. supports the FastCGI protocol. See the :ref:`FastCGI deployment documentation
  312. <howto-deployment-fastcgi>` for details. Requires the Python FastCGI module from
  313. `flup`_.
  314. .. _flup: http://www.saddi.com/software/flup/
  315. runserver [port or ipaddr:port]
  316. -------------------------------
  317. .. django-admin:: runserver
  318. Starts a lightweight development Web server on the local machine. By default,
  319. the server runs on port 8000 on the IP address 127.0.0.1. You can pass in an
  320. IP address and port number explicitly.
  321. If you run this script as a user with normal privileges (recommended), you
  322. might not have access to start a port on a low port number. Low port numbers
  323. are reserved for the superuser (root).
  324. DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through
  325. security audits or performance tests. (And that's how it's gonna stay. We're in
  326. the business of making Web frameworks, not Web servers, so improving this
  327. server to be able to handle a production environment is outside the scope of
  328. Django.)
  329. The development server automatically reloads Python code for each request, as
  330. needed. You don't need to restart the server for code changes to take effect.
  331. When you start the server, and each time you change Python code while the
  332. server is running, the server will validate all of your installed models. (See
  333. the ``validate`` command below.) If the validator finds errors, it will print
  334. them to standard output, but it won't stop the server.
  335. You can run as many servers as you want, as long as they're on separate ports.
  336. Just execute ``django-admin.py runserver`` more than once.
  337. Note that the default IP address, 127.0.0.1, is not accessible from other
  338. machines on your network. To make your development server viewable to other
  339. machines on the network, use its own IP address (e.g. ``192.168.2.1``) or
  340. ``0.0.0.0``.
  341. .. django-admin-option:: --adminmedia
  342. Use the ``--adminmedia`` option to tell Django where to find the various CSS
  343. and JavaScript files for the Django admin interface. Normally, the development
  344. server serves these files out of the Django source tree magically, but you'd
  345. want to use this if you made any changes to those files for your own site.
  346. Example usage::
  347. django-admin.py runserver --adminmedia=/tmp/new-admin-style/
  348. .. django-admin-option:: --noreload
  349. Use the ``--noreload`` option to disable the use of the auto-reloader. This
  350. means any Python code changes you make while the server is running will *not*
  351. take effect if the particular Python modules have already been loaded into
  352. memory.
  353. Example usage::
  354. django-admin.py runserver --noreload
  355. Examples of using different ports and addresses
  356. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  357. Port 8000 on IP address 127.0.0.1::
  358. django-admin.py runserver
  359. Port 8000 on IP address 1.2.3.4::
  360. django-admin.py runserver 1.2.3.4:8000
  361. Port 7000 on IP address 127.0.0.1::
  362. django-admin.py runserver 7000
  363. Port 7000 on IP address 1.2.3.4::
  364. django-admin.py runserver 1.2.3.4:7000
  365. Serving static files with the development server
  366. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  367. By default, the development server doesn't serve any static files for your site
  368. (such as CSS files, images, things under ``MEDIA_URL`` and so forth). If
  369. you want to configure Django to serve static media, read :ref:`howto-static-files`.
  370. shell
  371. -----
  372. .. django-admin:: shell
  373. Starts the Python interactive interpreter.
  374. Django will use IPython_, if it's installed. If you have IPython installed and
  375. want to force use of the "plain" Python interpreter, use the ``--plain``
  376. option, like so::
  377. django-admin.py shell --plain
  378. .. _IPython: http://ipython.scipy.org/
  379. sql <appname appname ...>
  380. -------------------------
  381. .. django-admin:: sql
  382. Prints the CREATE TABLE SQL statements for the given app name(s).
  383. sqlall <appname appname ...>
  384. ----------------------------
  385. .. django-admin:: sqlall
  386. Prints the CREATE TABLE and initial-data SQL statements for the given app name(s).
  387. Refer to the description of ``sqlcustom`` for an explanation of how to
  388. specify initial data.
  389. sqlclear <appname appname ...>
  390. ------------------------------
  391. .. django-admin:: sqlclear
  392. Prints the DROP TABLE SQL statements for the given app name(s).
  393. sqlcustom <appname appname ...>
  394. -------------------------------
  395. .. django-admin:: sqlcustom
  396. Prints the custom SQL statements for the given app name(s).
  397. For each model in each specified app, this command looks for the file
  398. ``<appname>/sql/<modelname>.sql``, where ``<appname>`` is the given app name and
  399. ``<modelname>`` is the model's name in lowercase. For example, if you have an
  400. app ``news`` that includes a ``Story`` model, ``sqlcustom`` will attempt
  401. to read a file ``news/sql/story.sql`` and append it to the output of this
  402. command.
  403. Each of the SQL files, if given, is expected to contain valid SQL. The SQL
  404. files are piped directly into the database after all of the models'
  405. table-creation statements have been executed. Use this SQL hook to make any
  406. table modifications, or insert any SQL functions into the database.
  407. Note that the order in which the SQL files are processed is undefined.
  408. sqlflush
  409. --------
  410. .. django-admin:: sqlflush
  411. Prints the SQL statements that would be executed for the :djadmin:`flush`
  412. command.
  413. sqlindexes <appname appname ...>
  414. --------------------------------
  415. .. django-admin:: sqlindexes
  416. Prints the CREATE INDEX SQL statements for the given app name(s).
  417. sqlreset <appname appname ...>
  418. ------------------------------
  419. .. django-admin:: sqlreset
  420. Prints the DROP TABLE SQL, then the CREATE TABLE SQL, for the given app name(s).
  421. sqlsequencereset <appname appname ...>
  422. --------------------------------------
  423. .. django-admin:: sqlsequencereset
  424. Prints the SQL statements for resetting sequences for the given app name(s).
  425. Sequences are indexes used by some database engines to track the next available
  426. number for automatically incremented fields.
  427. Use this command to generate SQL which will fix cases where a sequence is out
  428. of sync with its automatically incremented field data.
  429. startapp <appname>
  430. ------------------
  431. .. django-admin:: startapp
  432. Creates a Django app directory structure for the given app name in the current
  433. directory.
  434. startproject <projectname>
  435. --------------------------
  436. .. django-admin:: startproject
  437. Creates a Django project directory structure for the given project name in the
  438. current directory.
  439. This command is disabled when the ``--settings`` option to
  440. ``django-admin.py`` is used, or when the environment variable
  441. ``DJANGO_SETTINGS_MODULE`` has been set. To re-enable it in these
  442. situations, either omit the ``--settings`` option or unset
  443. ``DJANGO_SETTINGS_MODULE``.
  444. syncdb
  445. ------
  446. .. django-admin:: syncdb
  447. Creates the database tables for all apps in ``INSTALLED_APPS`` whose tables
  448. have not already been created.
  449. Use this command when you've added new applications to your project and want to
  450. install them in the database. This includes any apps shipped with Django that
  451. might be in ``INSTALLED_APPS`` by default. When you start a new project, run
  452. this command to install the default apps.
  453. .. admonition:: Syncdb will not alter existing tables
  454. ``syncdb`` will only create tables for models which have not yet been
  455. installed. It will *never* issue ``ALTER TABLE`` statements to match
  456. changes made to a model class after installation. Changes to model classes
  457. and database schemas often involve some form of ambiguity and, in those
  458. cases, Django would have to guess at the correct changes to make. There is
  459. a risk that critical data would be lost in the process.
  460. If you have made changes to a model and wish to alter the database tables
  461. to match, use the ``sql`` command to display the new SQL structure and
  462. compare that to your existing table schema to work out the changes.
  463. If you're installing the ``django.contrib.auth`` application, ``syncdb`` will
  464. give you the option of creating a superuser immediately.
  465. ``syncdb`` will also search for and install any fixture named ``initial_data``
  466. with an appropriate extension (e.g. ``json`` or ``xml``). See the
  467. documentation for ``loaddata`` for details on the specification of fixture
  468. data files.
  469. The :djadminopt:`--noinput` option may be provided to suppress all user
  470. prompts.
  471. test <app or test identifier>
  472. -----------------------------
  473. .. django-admin:: test
  474. Runs tests for all installed models. See :ref:`topics-testing` for more
  475. information.
  476. --failfast
  477. ~~~~~~~~~~
  478. .. versionadded:: 1.2
  479. Use the ``--failfast`` option to stop running tests and report the failure
  480. immediately after a test fails.
  481. testserver <fixture fixture ...>
  482. --------------------------------
  483. .. django-admin:: testserver
  484. .. versionadded:: 1.0
  485. Runs a Django development server (as in ``runserver``) using data from the
  486. given fixture(s).
  487. For example, this command::
  488. django-admin.py testserver mydata.json
  489. ...would perform the following steps:
  490. 1. Create a test database, as described in :ref:`topics-testing`.
  491. 2. Populate the test database with fixture data from the given fixtures.
  492. (For more on fixtures, see the documentation for ``loaddata`` above.)
  493. 3. Runs the Django development server (as in ``runserver``), pointed at
  494. this newly created test database instead of your production database.
  495. This is useful in a number of ways:
  496. * When you're writing :ref:`unit tests <topics-testing>` of how your views
  497. act with certain fixture data, you can use ``testserver`` to interact with
  498. the views in a Web browser, manually.
  499. * Let's say you're developing your Django application and have a "pristine"
  500. copy of a database that you'd like to interact with. You can dump your
  501. database to a fixture (using the ``dumpdata`` command, explained above),
  502. then use ``testserver`` to run your Web application with that data. With
  503. this arrangement, you have the flexibility of messing up your data
  504. in any way, knowing that whatever data changes you're making are only
  505. being made to a test database.
  506. Note that this server does *not* automatically detect changes to your Python
  507. source code (as ``runserver`` does). It does, however, detect changes to
  508. templates.
  509. .. django-admin-option:: --addrport [port number or ipaddr:port]
  510. Use ``--addrport`` to specify a different port, or IP address and port, from
  511. the default of 127.0.0.1:8000. This value follows exactly the same format and
  512. serves exactly the same function as the argument to the ``runserver`` subcommand.
  513. Examples:
  514. To run the test server on port 7000 with ``fixture1`` and ``fixture2``::
  515. django-admin.py testserver --addrport 7000 fixture1 fixture2
  516. django-admin.py testserver fixture1 fixture2 --addrport 7000
  517. (The above statements are equivalent. We include both of them to demonstrate
  518. that it doesn't matter whether the options come before or after the fixture
  519. arguments.)
  520. To run on 1.2.3.4:7000 with a ``test`` fixture::
  521. django-admin.py testserver --addrport 1.2.3.4:7000 test
  522. validate
  523. --------
  524. .. django-admin:: validate
  525. Validates all installed models (according to the ``INSTALLED_APPS`` setting)
  526. and prints validation errors to standard output.
  527. Default options
  528. ===============
  529. Although some subcommands may allow their own custom options, every subcommand
  530. allows for the following options:
  531. .. django-admin-option:: --pythonpath
  532. Example usage::
  533. django-admin.py syncdb --pythonpath='/home/djangoprojects/myproject'
  534. Adds the given filesystem path to the Python `import search path`_. If this
  535. isn't provided, ``django-admin.py`` will use the ``PYTHONPATH`` environment
  536. variable.
  537. Note that this option is unnecessary in ``manage.py``, because it takes care of
  538. setting the Python path for you.
  539. .. _import search path: http://diveintopython.org/getting_to_know_python/everything_is_an_object.html
  540. .. django-admin-option:: --settings
  541. Example usage::
  542. django-admin.py syncdb --settings=mysite.settings
  543. Explicitly specifies the settings module to use. The settings module should be
  544. in Python package syntax, e.g. ``mysite.settings``. If this isn't provided,
  545. ``django-admin.py`` will use the ``DJANGO_SETTINGS_MODULE`` environment
  546. variable.
  547. Note that this option is unnecessary in ``manage.py``, because it uses
  548. ``settings.py`` from the current project by default.
  549. .. django-admin-option:: --traceback
  550. Example usage::
  551. django-admin.py syncdb --traceback
  552. By default, ``django-admin.py`` will show a simple error message whenever an
  553. error occurs. If you specify ``--traceback``, ``django-admin.py`` will
  554. output a full stack trace whenever an exception is raised.
  555. .. django-admin-option:: --verbosity
  556. Example usage::
  557. django-admin.py syncdb --verbosity 2
  558. Use ``--verbosity`` to specify the amount of notification and debug information
  559. that ``django-admin.py`` should print to the console.
  560. * ``0`` means no output.
  561. * ``1`` means normal output (default).
  562. * ``2`` means verbose output.
  563. Common options
  564. ==============
  565. The following options are not available on every commands, but they are
  566. common to a number of commands.
  567. .. django-admin-option:: --locale
  568. Use the ``--locale`` or ``-l`` option to specify the locale to process.
  569. If not provided all locales are processed.
  570. .. django-admin-option:: --noinput
  571. Use the ``--noinput`` option to suppress all user prompting, such as "Are
  572. you sure?" confirmation messages. This is useful if ``django-admin.py`` is
  573. being executed as an unattended, automated script.
  574. Extra niceties
  575. ==============
  576. Syntax coloring
  577. ---------------
  578. The ``django-admin.py`` / ``manage.py`` commands that output SQL to standard
  579. output will use pretty color-coded output if your terminal supports
  580. ANSI-colored output. It won't use the color codes if you're piping the
  581. command's output to another program.
  582. Bash completion
  583. ---------------
  584. If you use the Bash shell, consider installing the Django bash completion
  585. script, which lives in ``extras/django_bash_completion`` in the Django
  586. distribution. It enables tab-completion of ``django-admin.py`` and
  587. ``manage.py`` commands, so you can, for instance...
  588. * Type ``django-admin.py``.
  589. * Press [TAB] to see all available options.
  590. * Type ``sql``, then [TAB], to see all available options whose names start
  591. with ``sql``.
  592. See :ref:`howto-custom-management-commands` for how to add customized actions.