can_introspect_default feature

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

can_introspect_default feature

maxi-2
Hi,

How supposed to can_introspect_default must work?

I'm working on django firebird backend and I'm trying to figured out how this feature works, but the schema tests fails. 
This default is at database level or django level?

If I define a field with a default value, and do a metadata introspection over this field to know if default value is defined, it always returns True.

I hope be clear (sorry for my bad english)

---
Maxi

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/24d65283-5bca-4253-8365-1f2b2d5a3307%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: can_introspect_default feature

Tim Graham-2
Hi Maxi,

Did you take a look at the relevant commit that introduced the flag?
https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc

On Tuesday, October 18, 2016 at 9:51:46 AM UTC-4, Maximiliano Robaina wrote:
Hi,

How supposed to can_introspect_default must work?

I'm working on django firebird backend and I'm trying to figured out how this feature works, but the schema tests fails. 
This default is at database level or django level?

If I define a field with a default value, and do a metadata introspection over this field to know if default value is defined, it always returns True.

I hope be clear (sorry for my bad english)

---
Maxi

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/05234368-c59e-4961-a98f-846716b410af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: can_introspect_default feature

maxi-2
Hi Tim,

Thanks for response.

El martes, 18 de octubre de 2016, 12:07:34 (UTC-3), Tim Graham escribió:
Hi Maxi,

Did you take a look at the relevant commit that introduced the flag?
<a href="https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFtCRduSUMOqxxj4FkmHyuAEqn4YA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFtCRduSUMOqxxj4FkmHyuAEqn4YA&#39;;return true;">https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc

Yes, I was looking into this changeset, but I can't understand yet what "And that the default is no longer set in the database." means in test_add_field_default_dropped [1].
field.default contains the column default definition not the default value of the some table record, Is it that correct?, So, why this must be None?



[1] https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc#diff-888b45a0a8f38ee67e8d22403cf994dbR1371


Regards 




On Tuesday, October 18, 2016 at 9:51:46 AM UTC-4, Maximiliano Robaina wrote:
Hi,

How supposed to can_introspect_default must work?

I'm working on django firebird backend and I'm trying to figured out how this feature works, but the schema tests fails. 
This default is at database level or django level?

If I define a field with a default value, and do a metadata introspection over this field to know if default value is defined, it always returns True.

I hope be clear (sorry for my bad english)

---
Maxi

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/f2e735f6-967e-4391-8623-48c1f7e7d3b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: can_introspect_default feature

Tim Graham-2
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.

On Thursday, October 20, 2016 at 8:29:29 AM UTC-4, Maximiliano Robaina wrote:
Hi Tim,

Thanks for response.

El martes, 18 de octubre de 2016, 12:07:34 (UTC-3), Tim Graham escribió:
Hi Maxi,

Did you take a look at the relevant commit that introduced the flag?
<a href="https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFtCRduSUMOqxxj4FkmHyuAEqn4YA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFtCRduSUMOqxxj4FkmHyuAEqn4YA&#39;;return true;">https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc

Yes, I was looking into this changeset, but I can't understand yet what "And that the default is no longer set in the database." means in test_add_field_default_dropped [1].
field.default contains the column default definition not the default value of the some table record, Is it that correct?, So, why this must be None?



[1] <a href="https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc#diff-888b45a0a8f38ee67e8d22403cf994dbR1371" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc%23diff-888b45a0a8f38ee67e8d22403cf994dbR1371\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFlyFGzLuIyBumJDE4e5a1Mf6pzHQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc%23diff-888b45a0a8f38ee67e8d22403cf994dbR1371\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFlyFGzLuIyBumJDE4e5a1Mf6pzHQ&#39;;return true;">https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc#diff-888b45a0a8f38ee67e8d22403cf994dbR1371


Regards 




On Tuesday, October 18, 2016 at 9:51:46 AM UTC-4, Maximiliano Robaina wrote:
Hi,

How supposed to can_introspect_default must work?

I'm working on django firebird backend and I'm trying to figured out how this feature works, but the schema tests fails. 
This default is at database level or django level?

If I define a field with a default value, and do a metadata introspection over this field to know if default value is defined, it always returns True.

I hope be clear (sorry for my bad english)

---
Maxi

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/64ab186f-de5c-42c7-99c9-d3e89225877b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: can_introspect_default feature

Chris Foresman
Out of curiosity, why isn't this added as part of the column definition? Isn't it better to enforce the default at the DB layer? Or is it to account for differences across database types? (This trips me up a lot because we have a lot of different apps/processes which have to touch the database and only the API server is written in Django.)


On Thursday, October 20, 2016 at 7:53:23 AM UTC-5, Tim Graham wrote:
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.

On Thursday, October 20, 2016 at 8:29:29 AM UTC-4, Maximiliano Robaina wrote:
Hi Tim,

Thanks for response.

El martes, 18 de octubre de 2016, 12:07:34 (UTC-3), Tim Graham escribió:
Hi Maxi,

Did you take a look at the relevant commit that introduced the flag?
<a href="https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFtCRduSUMOqxxj4FkmHyuAEqn4YA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFtCRduSUMOqxxj4FkmHyuAEqn4YA&#39;;return true;">https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc

Yes, I was looking into this changeset, but I can't understand yet what "And that the default is no longer set in the database." means in test_add_field_default_dropped [1].
field.default contains the column default definition not the default value of the some table record, Is it that correct?, So, why this must be None?



[1] <a href="https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc#diff-888b45a0a8f38ee67e8d22403cf994dbR1371" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc%23diff-888b45a0a8f38ee67e8d22403cf994dbR1371\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFlyFGzLuIyBumJDE4e5a1Mf6pzHQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc%23diff-888b45a0a8f38ee67e8d22403cf994dbR1371\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFlyFGzLuIyBumJDE4e5a1Mf6pzHQ&#39;;return true;">https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc#diff-888b45a0a8f38ee67e8d22403cf994dbR1371


Regards 




On Tuesday, October 18, 2016 at 9:51:46 AM UTC-4, Maximiliano Robaina wrote:
Hi,

How supposed to can_introspect_default must work?

I'm working on django firebird backend and I'm trying to figured out how this feature works, but the schema tests fails. 
This default is at database level or django level?

If I define a field with a default value, and do a metadata introspection over this field to know if default value is defined, it always returns True.

I hope be clear (sorry for my bad english)

---
Maxi

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/05dd4112-84fd-4a1c-8d5c-0fbeac202649%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: can_introspect_default feature

Tim Graham-2
It isn't always possible to transform arbitrary Python defaults (particularly callables) into SQL.

A search query would help you answer a question like this. I typed
"django database column defaults site:code.djangoproject.com" into Google and found
https://code.djangoproject.com/ticket/470 among other tickets.

...or searching the archives of this mailing list for "django database defaults" gives discussions such as:
https://groups.google.com/d/topic/django-developers/nrVzOnHBk64/discussion

On Tuesday, October 25, 2016 at 3:39:54 PM UTC-4, Chris Foresman wrote:
Out of curiosity, why isn't this added as part of the column definition? Isn't it better to enforce the default at the DB layer? Or is it to account for differences across database types? (This trips me up a lot because we have a lot of different apps/processes which have to touch the database and only the API server is written in Django.)


On Thursday, October 20, 2016 at 7:53:23 AM UTC-5, Tim Graham wrote:
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.

On Thursday, October 20, 2016 at 8:29:29 AM UTC-4, Maximiliano Robaina wrote:
Hi Tim,

Thanks for response.

El martes, 18 de octubre de 2016, 12:07:34 (UTC-3), Tim Graham escribió:
Hi Maxi,

Did you take a look at the relevant commit that introduced the flag?
<a href="https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFtCRduSUMOqxxj4FkmHyuAEqn4YA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFtCRduSUMOqxxj4FkmHyuAEqn4YA&#39;;return true;">https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc

Yes, I was looking into this changeset, but I can't understand yet what "And that the default is no longer set in the database." means in test_add_field_default_dropped [1].
field.default contains the column default definition not the default value of the some table record, Is it that correct?, So, why this must be None?



[1] <a href="https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc#diff-888b45a0a8f38ee67e8d22403cf994dbR1371" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc%23diff-888b45a0a8f38ee67e8d22403cf994dbR1371\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFlyFGzLuIyBumJDE4e5a1Mf6pzHQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc%23diff-888b45a0a8f38ee67e8d22403cf994dbR1371\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFlyFGzLuIyBumJDE4e5a1Mf6pzHQ&#39;;return true;">https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc#diff-888b45a0a8f38ee67e8d22403cf994dbR1371


Regards 




On Tuesday, October 18, 2016 at 9:51:46 AM UTC-4, Maximiliano Robaina wrote:
Hi,

How supposed to can_introspect_default must work?

I'm working on django firebird backend and I'm trying to figured out how this feature works, but the schema tests fails. 
This default is at database level or django level?

If I define a field with a default value, and do a metadata introspection over this field to know if default value is defined, it always returns True.

I hope be clear (sorry for my bad english)

---
Maxi

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/f68e1d3d-42f4-4cc2-ae25-31226cd2f980%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: can_introspect_default feature

maxi-2
In reply to this post by Tim Graham-2
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?
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.




 


On Thursday, October 20, 2016 at 8:29:29 AM UTC-4, Maximiliano Robaina wrote:
Hi Tim,

Thanks for response.

El martes, 18 de octubre de 2016, 12:07:34 (UTC-3), Tim Graham escribió:
Hi Maxi,

Did you take a look at the relevant commit that introduced the flag?
<a href="https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFtCRduSUMOqxxj4FkmHyuAEqn4YA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFtCRduSUMOqxxj4FkmHyuAEqn4YA&#39;;return true;">https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc

Yes, I was looking into this changeset, but I can't understand yet what "And that the default is no longer set in the database." means in test_add_field_default_dropped [1].
field.default contains the column default definition not the default value of the some table record, Is it that correct?, So, why this must be None?



[1] <a href="https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc#diff-888b45a0a8f38ee67e8d22403cf994dbR1371" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc%23diff-888b45a0a8f38ee67e8d22403cf994dbR1371\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFlyFGzLuIyBumJDE4e5a1Mf6pzHQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2F75303b01a9cc900eebf1f27ba0bc6508334242fc%23diff-888b45a0a8f38ee67e8d22403cf994dbR1371\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFlyFGzLuIyBumJDE4e5a1Mf6pzHQ&#39;;return true;">https://github.com/django/django/commit/75303b01a9cc900eebf1f27ba0bc6508334242fc#diff-888b45a0a8f38ee67e8d22403cf994dbR1371


Regards 




On Tuesday, October 18, 2016 at 9:51:46 AM UTC-4, Maximiliano Robaina wrote:
Hi,

How supposed to can_introspect_default must work?

I'm working on django firebird backend and I'm trying to figured out how this feature works, but the schema tests fails. 
This default is at database level or django level?

If I define a field with a default value, and do a metadata introspection over this field to know if default value is defined, it always returns True.

I hope be clear (sorry for my bad english)

---
Maxi

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/df9f8a7d-eba6-4108-9506-a3a69e2edc0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: can_introspect_default feature

Shai Berger
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.
Reply | Threaded
Open this post in threaded view
|

Re: can_introspect_default feature

maxi-2

Hi Shai,


El martes, 25 de abril de 2017, 18:28:57 (UTC-3), Shai Berger escribió:
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.

Yes, I understand that and I agree. I my case, Firebird has an strange behavior when you add a new not null field with a default  and then remove the default definition.
I must to implement other strategies.

Regards
Maxi


 

HTH,
        Shai.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/c7f2d7d3-a540-486e-9e61-cf89e3911abf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.