Opened 7 years ago

Closed 7 months ago

#27676 closed New feature (fixed)

MariaDB 10.2 supports defaults for text columns

Reported by: Adam Johnson Owned by: Adam Johnson
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: me@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django has workaround code for MySQL's deficiency not supporting DEFAULT for TEXT, BLOB, and JSON columns, but MariaDB 10.2 fixes this ( see https://mariadb.com/kb/en/mariadb/what-is-mariadb-102/: "BLOB and TEXT fields can now have a DEFAULT value." ).

Django should allow DEFAULT for these columns when on MariaDB 10.2+.

Change History (10)

comment:1 by Tim Graham, 7 years ago

Triage Stage: UnreviewedSomeday/Maybe
Type: BugNew feature

First some consensus is needed about whether Django should officially support MariaDB.

comment:2 by Adam Johnson, 7 years ago

Thanks, I missed that thread, commented

comment:3 by Tim Graham, 7 years ago

Has patch: set
Triage Stage: Someday/MaybeReady for checkin

comment:4 by Tim Graham, 7 years ago

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

On the PR, Adam said, "I was thinking of forming a better plan around MariaDB first."

comment:5 by Mariusz Felisiak, 5 years ago

Django 3.0 will officially support MariaDB 10.1+. I think it's time to change this feature flag. Adam, can you resubmit your patch?

comment:6 by Adam Johnson, 5 years ago

Patch needs improvement: unset
Last edited 5 years ago by Mariusz Felisiak (previous) (diff)

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 7da6a28a:

Fixed #27676 -- Allowed BLOB/TEXT defaults on MariaDB 10.2.1+.

comment:8 by Tobias Krönke, 7 months ago

Could we skip the default if it's the empty string for MySQL? Explicitly setting the empty string prevents the ALGORITHM=INSTANT magic from adding the column without table copying. This would be a huge performance improvement for many users. I have seen so many issues where people would like to add new columns to very large tables efficiently. MySQL has this now built-in, but django prevents it by redudantly specifying the empty string as default. This is enough and makes the instant algorithm work:

ALTER TABLE `<table name>` ADD COLUMN `<column name>` longtext NOT NULL;

Same for CHAR and VARCHAR.

BTW, there is an annoying workaround for this for now: in a first migration, we add the new column by adding my_field = models.TextField(blank=True, default=None) and then we change it to my_field = models.TextField(blank=True) and generate another migration. The 1st migration adds the column without default expression. And guess what, that 2nd migration is a no-op. That's because the default is actually only a django thing, not a DB thing.

Last edited 7 months ago by Tobias Krönke (previous) (diff)

comment:9 by Tobias Krönke, 7 months ago

Resolution: fixed
Status: closednew

comment:10 by Tim Graham, 7 months ago

Resolution: fixed
Status: newclosed

Please open a new ticket rather than reopening an old one.

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