django model field comment in database

前端 未结 3 1687
灰色年华
灰色年华 2021-01-18 19:57

this is the model class(django version 2.0)

class Host(models.Model):
    host_id=models.CharField(max_length=20,primary_key=True)
    host_label=models.Char         


        
3条回答
  •  情歌与酒
    2021-01-18 20:32

    Looks like currently you can't, at least not in Django. I was able to find 2 similar request tickets in Django:

    #13867 Feature request: Comments in Django models saved to database schema

    Opened 9 years ago and dismissed as wontfix an year later, with rationale along the lines of "it doesn't have a good usefulness/noise ratio. The ORM doesn't aim at providing a Python interface for every feature of the supported database engine"

    #18468 Add the ability to define comments in table / columns

    Opened 7 years ago, marked as a duplicate of the above, end of story until... plot twist! Reopened on 2018-03, went trough discussion on mailing list, and now marked as Accepted. Original rejecter said "I think we could implement that feature. (Yes I changed my mind from six years ago when I wontfix'd the ticket.)"

    So now this only requires an implementation / patch / PR , which hasn't been done yet (but anyone can contribute!)

    The ticket submitter started making a patch, and created a Django App that fixes the problem for Fields (using verbose_name and help_text attributes) on PostgreSQL backends. You're using MySQL, but it might be trivial to adapt it:

    https://github.com/vanadium23/django-db-comments

提交回复
热议问题