gpt4 book ai didi

django - 如何使用相应的 Django 模型为 Postgres DB 中的列添加 "description"?

转载 作者:行者123 更新时间:2023-11-29 13:15:39 25 4
gpt4 key购买 nike

例如,在此表中,我希望能够在 Django ORM 层添加“描述”文本,并将其反射(reflect)在数据库级别。

test=# \d+ django_model
Table "public.django_model"
Column | Type | Modifiers | Description
--------+---------+-----------+-------------
i | integer | |
j | integer | |
Indexes:
"mi" btree (i) - Tablespace: "testspace"
"mj" btree (j)
Has OIDs: no

最佳答案

我想你做不到。这是 https://code.djangoproject.com/ticket/13867要求。关闭 6 ya 为“不会做”。

你仍然可以使用 postgres COMMENT 扩展,例如:

t=# create table t (i int, t text);
CREATE TABLE
Time: 12.068 ms
t=# comment on column t.i is 'some description';
COMMENT
Time: 2.994 ms
t=# \d+ t
Table "postgres.t"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+----------+--------------+------------------
i | integer | | | | plain | | some description
t | text | | | | extended | |

关于django - 如何使用相应的 Django 模型为 Postgres DB 中的列添加 "description"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49399679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com