from django.db import models
classQuestion(models.Model):
text = models.TextField(db_comment="Poll question")
pub_date = models.DateTimeField(
db_comment="Date and time when the question was published",
)
classMeta:
db_table_comment ="Poll questions"classAnswer(models.Model):
question = models.ForeignKey(
Question,
on_delete=models.CASCADE,
db_comment="Reference to a question",
)
answer = models.TextField(db_comment="Question answer")
classMeta:
db_table_comment ="Question answers"
テーブル定義の内容は以下のとおりです。
psqlでの\d+ example_question;(カラムのコメントを確認)の実行結果:
1
2
3
4
5
6
7
8
9
10
Table"public.example_question"Column|Type|Collation|Nullable|Default|Storage| Compression | Stats target | Description
----------+--------------------------+-----------+----------+----------------------------------+----------+-------------+--------------+-----------------------------------------------
id | bigint ||notnull|generatedbydefaultasidentity| plain ||| text | text ||notnull|| extended ||| Poll question
pub_date |timestampwith time zone||notnull|| plain ||| Date and time when the question was published
Indexes:
"example_question_pkey"PRIMARYKEY, btree (id)
Referenced by:
TABLE"example_answer"CONSTRAINT"example_answer_question_id_4e8f5232_fk_example_question_id"FOREIGNKEY (question_id) REFERENCES example_question(id) DEFERRABLEINITIALLYDEFERRED