... 期化されます。ここで、 geodjango プロジェクトの中に world Django アプリケーションを作成します: / $ cd geodjango $ python manage.py startapp world ...\> cd geodjango ...\> py manage.py startapp world settings.py の設定 geodjango プロジェクトの設定は g ... デルを定義した後、データベースと同期する必要があります。まず、データベースマイグレーションを作成してください: / $ python manage.py makemigrations Migrations for 'world': world/migrations/0001_initial.py: + Create model WorldBorder ...\> py manage.py ... ions/0001_initial.py: + Create model WorldBorder WorldBorder モデルのテーブルを生成するSQLを見てみましょう: / $ python manage.py sqlmigrate world 0001 ...\> py manage.py sqlmigrate world 0001 このコマンドを実行すると、次の出力が生成されるはずです: ... ... ーブルを使うので、使い始める前にデータベースにテーブルを作る必要があります。以下のコマンドを実行してください: / $ python manage.py migrate ...\> py manage.py migrate migrate コマンドは INSTALLED_APPS の設定を参照するとともに、 mysite/settings.py ファ ... れで Django は、 polls アプリケーションが含まれていることを認識できます。もうひとつコマンドを実行しましょう: / $ python manage.py makemigrations polls ...\> py manage.py makemigrations polls 次のようなものが表示されるはずです: Migrations for 'polls' ... を手動で微調整したいというときのために、マイグレーションは人間可読なファイルとして設計されています。 もし興味があれば python manage.py check を実行することもできます; これはマイグレーションを作成したりデータベースにふれることなく、プロジェクトに何か問題が ... ... パッケージ名と名前が衝突します) を使わないようにしましょう。 startproject が何を作成したかをみてみましょう: djangotutorial/ manage.py mysite/ __init__.py settings.py urls.py asgi.py wsgi.py ファイルはそれぞれ以下のような役割を持っています: manage.py : D ... jango プロジェクトに対する様々な操作を行うためのコマンドラインユーティリティです。詳しくは django-admin と manage.py 内の manage.py を参照してください。 mysite/ : これは実際のプロジェクト用のPythonパッケージを含むディレクトリです。このデ ... するか確認しましょう。まだであれば、 djangotutorial ディレクトリに移動し、以下のコマンドを実行してください。 / $ python manage.py runserver ...\> py manage.py runserver コマンドライン上で下記の出力が確認できるでしょう: Performing system checks... Sy ... ... tographic signing , several CSRF improvements , and simple clickjacking protection . An updated default project layout and manage.py that removes the "magic" from prior versions. And for those who don't like the new layout, you can use custom project a ... nds more comprehensively. See the documentation for more details and concrete examples. Updated default project layout and manage.py Django 1.4 ships with an updated default project layout and manage.py file for the startproject management command. The ... se fix some issues with the previous manage.py handling of Python import paths that caused double imports, trouble moving from development to deployment, and other di ... ... スイートの中で実行した時には失敗してしまうという状況が発生することがあります。 テストの実行 テストが書けたら、プロジェクトの manage.py ユーティリティの test コマンドでテストが実行できます。 $ ./manage.py test Test discovery is based on the unittest modul ... in test discovery . By default, this will discover tests in any file named test*.py under the current working directory. ./manage.py test に好きな数の「テストラベル」を与えることで、特定のテストを指定することもできます。各テストラベルには、パッケージ、 ... ット区切りの Python パスを指定します。たとえば、以下のように指定します。 # Run all the tests in the animals.tests module $ ./manage.py test animals.tests # Run all the tests found within the 'animals' package $ ./manage.py test animals # Run just one tes ... ... たとえば、フィールドを追加してモデルを削除するなど、モデルに変更を加えてから、 makemigrations を実行してください。 $ python manage.py makemigrations Migrations for 'books' : books/migrations/0003_auto.py: ~ Alter field author on book すると、あなたが書い ... 。 問題なく新しいマイグレーションファイルが生成されたら、期待通りに変更が行われるように、データベースに適用します: $ python manage.py migrate Operations to perform: Apply all migrations: books Running migrations: Applying books.0003_auto... OK マイグレー ... ーションに、自動生成された名前ではなく、意味のある名前を与えたければ、 makemigrations --name オプションが使えます。 $ python manage.py makemigrations --name changed_my_model your_app_label Executing sqlmigrate The sqlmigrate command takes migration names ... ... ないようにします。 すべてのオプションのリストは、次のコマンドを実行してコマンドのヘルプから参照してください。 / $ python manage.py collectstatic --help ...\> py manage.py collectstatic --help 無視パターンリストをカスタマイズする デフォルトの無視パター ... -admin findstatic staticfile [staticfile ...] 有効な検索機能を使用して、1つ以上の相対パスを検索します。 例: / $ python manage.py findstatic css/base.css admin/js/core.js Found 'css/base.css' here: /home/special.polls.com/core/static/css/base.css /h ... core/static/css/base.css Found 'admin/js/core.js' here: /home/polls.com/src/django/contrib/admin/media/js/core.js ...\> py manage.py findstatic css\base.css admin\js\core.js Found 'css/base.css' here: /home/special.polls.com/core/static/css/base.css /h ... ... t the reference directly on the affected column, so they are not always visible. The effect of this change is that running manage.py reset and similar commands against an existing database may generate SQL with the new form of constraint name, while th ... odifying nonexistent constraints. If you need to work around this, there are two methods available: Redirect the output of manage.py to a file, and edit the generated SQL to use the correct constraint names before executing it. Examine the output of ma ... e the new-style constraint names, and use that as a guide to rename existing constraints in your database. Name changes in manage.py A few of the options to manage.py have changed with the addition of fixture support: There are new dumpdata and loaddat ... ... ョンか PYTHONWARNINGS 環境変数を使って有効化する必要があります。例えば、テスト実行中に警告を表示するには: / $ python -Wa manage.py test ...\> py -Wa manage.py test Djangoのテストランナーを使っていない場合、廃止予定警告が隠されることのないように、コン ... い環境が設定されたら、 テストスイートを実行します 。テストの出力に表示されるように、廃止予定の警告を有効にすると便利です。 ( manage.py runserver を使用してアプリケーションを手動でテストする場合は、フラグを使用することもできます) / $ python -Wa manage ... .py test ...\> py -Wa manage.py test テストを実行したら、テストに失敗した点をすべて修正しましょう。リリースノートの内容を心に留めながらコードをリファク ... ... 付属しており、既存のデータベースを調査することでモデルを作成できます。次のコマンドを実行すると出力が表示できます。 $ python manage.py inspectdb 通常の Unix 出力のリダイレクトにより、ファイルとして保存します。 $ python manage.py inspectdb > models.py この ... on パッケージの中に配置します。そして、アプリを INSTALLED_APPS の設定に追加します。 デフォルトでは、 inspectdb は未管理 (unmanaged) なモデルを作成します。つまり、モデルの Meta クラス内の managed = False により、Django はテーブルの作成・変更・削除を管理 ... odel ): id = models . IntegerField ( primary_key = True ) first_name = models . CharField ( max_length = 70 ) class Meta : managed = False db_table = "CENSUS_PERSONS" Django にテーブルのライフサイクルの管理を行ってほしい場合、上記の managed オプションを ... 2026年10月08日