Opened 6 years ago

Closed 5 years ago

Last modified 4 years ago

#13867 closed New feature (wontfix)

Feature request: Comments in Django models saved to database schema

Reported by: Renato Alves Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently there is no way to make comments in the schema via Django. The only way is to alter the tables and add the comments manually in the database.

This feature request presents one possible implementation.

For comments at the table level, use the first line of the Model docstring, truncating it depending on backend limitations.
For comments at the column level, include a comment attribute on the Field declaration.

class Dummy(Model):
    """This comment goes into the schema.
    This and the following won't
    ...
    """
    dummy_name = CharField(max_length=20, comment="All dummies should have names right?")
    ...

In addition, a specific syntax could be used in the docstring to prevent undesired comments in already existing code to be transfered to the database.

Change History (8)

comment:1 Changed 6 years ago by Łukasz Rekucki

I'm assuming this refers to PostgreSQL specific COMMENT extension to SQL. Instead of adding a new comment argument to fields, help_text could be reused. Table comments should probably go into the model's Meta with all the other stuff (like verbose_name). Using a special docstring syntax adds unnecessary complexity and magic.

comment:2 Changed 6 years ago by Renato Alves

For PostgreSQL yes, for MySQL something like:

 CREATE TABLE `bacteria`.`dummy` (
`dummy_name` VARCHAR ( 20 ) NOT NULL COMMENT 'All dummies should have names right?'
) ENGINE = InnoDB COMMENT = 'This comment goes into the schema.'

I agree with the point about the docstring magic, however for the column comment I think they should be kept separate.
One may want to include a content specific comment in the database and a different message in help_text as user guideline.

comment:3 Changed 6 years ago by Renato Alves

Summary: Feature request: docstring and comments in Django models saved to database schemaFeature request: Comments in Django models saved to database schema

comment:4 Changed 6 years ago by Brodie Rao

Triage Stage: UnreviewedDesign decision needed

comment:5 Changed 6 years ago by Graham King

Severity: Normal
Type: New feature

comment:6 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

comment:7 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset
Resolution: wontfix
Status: newclosed
UI/UX: unset

I understand the idea, but I'm afraid 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 engines. Its goal is "just" to provide an OO API.

Since there's neither a clean API proposal, nor a patch, nor a convincing explanation of the value added by this feature, I'm going to close this ticket.

comment:8 Changed 4 years ago by Aymeric Augustin

#18468 is a duplicate with a patch.

Note: See TracTickets for help on using tickets.
Back to Top