Opened 9 years ago
Closed 2 years 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 , 9 years ago
| Triage Stage: | Unreviewed → Someday/Maybe |
|---|---|
| Type: | Bug → New feature |
comment:4 by , 9 years ago
| Patch needs improvement: | set |
|---|---|
| Triage Stage: | Ready for checkin → Accepted |
On the PR, Adam said, "I was thinking of forming a better plan around MariaDB first."
comment:5 by , 6 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 , 6 years ago
| Patch needs improvement: | unset |
|---|
comment:8 by , 2 years 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.
comment:9 by , 2 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → new |
comment:10 by , 2 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Please open a new ticket rather than reopening an old one.
First some consensus is needed about whether Django should officially support MariaDB.