Hi Maxi,
On Tuesday 25 April 2017 20:21:47 Maximiliano Robaina wrote:
> Hi,
>
> Sorry but a need to return to this
>
> El jueves, 20 de octubre de 2016, 9:53:23 (UTC-3), Tim Graham escribió:
> > The 'default' model field option is used in Python rather than in the
> > database. SchemaEditor might set a column default to ease populating a
> > value on existing rows but that default shouldn't be left in the column's
> > definition. self.assertIsNone(field.default) means that the column
> > doesn't have a default.
>
> Ok, you say that SchemaEditor set a column default to ease populating a
> value on existing row. Which sql engine works in that way?
All of them, as far as I know.
> I was reading into postgresql docs [1] and it says that add a column
> default definition "Note that this doesn't affect any existing rows in the
> table, it just changes the default for future INSERT commands.". So, I
> don't undertend why add a database default definition is useful if later we
> need to remove it.
>
That statement is correct if it refers to adding a default definition to an
existing column, but SchemaEditor uses defaults only when it adds new columns.
if you add a new column to a table that already has rows, then the easiest way
to set a value for all existing rows is to define it as default. If the column
is not nullable, you actually cannot add it without a default.
And yet, some Python defaults cannot be represented in SQL (mostly functions),
and we'd much rather use Python defaults. Experience (in South) has shown that
defaults in the database, when used carelessly, cause problems, so we try to
keep them out.
HTH,
Shai.