aerich icon indicating copy to clipboard operation
aerich copied to clipboard

aerich doesn't respect default in TextField

Open metakot opened this issue 4 years ago • 2 comments

Add the text field

text = fields.TextField(default='')

run aerich migrate the result is

{
  "upgrade": [
    "ALTER TABLE \"company\" ADD \"text\" TEXT NOT NULL"
  ],
  "downgrade": [
    "ALTER TABLE \"company\" DROP COLUMN \"text\""
  ]
}

metakot avatar Nov 18 '20 18:11 metakot

see https://stackoverflow.com/questions/28002029/mysql-default-value-for-text-column-behaving-erratically-why

long2ice avatar Nov 19 '20 01:11 long2ice

That's a 14 years old bug in MySQL, according to https://stackoverflow.com/questions/3466872/why-cant-a-text-column-have-a-default-value-in-mysql Ok, I see a reason why it is implemented as is.

But it is impossible to add TextField to existing table without specifying null=True or default=''. And nullable text (and char) fields is a bad practice, because you would have two different empty values (Null and empty string).

So it can be done with normal RDBMS, like PostgreSQL.

metakot avatar Nov 20 '20 17:11 metakot