I would like to propose making Fields.default to rely on the database generated defaults where possible. This could be implemented by having some constants like fields.CURRENT_TIMESTAMP, etc. The tricky part here is to detect database backend specific capabilities and have a python equivalent fallback.
Any thoughts?
Hi Loic,
Agree with having a db_default kwarg.
I am not using multiple databases so no experiance with db routers. So how would should we handle routing between different databases when the db_default value is not compatible with that backend? for example Model.save(using='mysql_db') should we than use the Field.default to generate the default value (which is not how it works today, that the default is computed at instance creation). I would prefer in such a case to rely on the database to handle the situation by omitting that field from the columns list, so mysql for example would set a non nullable varchar column to an empty string, where with other databases it would cause an IntegrityError exception. and that db_default and default kwargs cannot be used togethor.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/125BCDAB-728B-4BAA-A8AB-38BA0842B709%40gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CANJp-yjsEthdkNQUaUKW3DfgyeigtjyZMYQoGteX%2BQ4MM4uPAw%40mail.gmail.com.
Hi Loic,
Agree with having a db_default kwarg.
I am not using multiple databases so no experiance with db routers. So how would should we handle routing between different databases when the db_default value is not compatible with that backend? for example Model.save(using='mysql_db') should we than use the Field.default to generate the default value (which is not how it works today, that the default is computed at instance creation). I would prefer in such a case to rely on the database to handle the situation by omitting that field from the columns list, so mysql for example would set a non nullable varchar column to an empty string, where with other databases it would cause an IntegrityError exception. and that db_default and default kwargs cannot be used togethor.
--
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 django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAGdCwBsHa%2BGXJSB6fay%3DbM%2B-3qV0y5oSuDNd4m05QM1PPdfKrw%40mail.gmail.com.
--
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 django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAGdCwBsHa%2BGXJSB6fay%3DbM%2B-3qV0y5oSuDNd4m05QM1PPdfKrw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/6708A498-F62B-4651-B52D-B40FD1E47DED%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
I would like to propose making Fields.default to rely on the database generated defaults where possible. This could be implemented by having some constants like fields.CURRENT_TIMESTAMP, etc. The tricky part here is to detect database backend specific capabilities and have a python equivalent fallback.
Any thoughts?
On Aug 3, 2015 3:36 AM, "Anssi Kääriäinen" <akaa...@gmail.com> wrote:
>
> On Wednesday, July 29, 2015 at 8:05:10 AM UTC+3, Aron Podrigal wrote:
>>
>> I would like to propose making Fields.default to rely on the database generated defaults where possible. This could be implemented by having some constants like fields.CURRENT_TIMESTAMP, etc. The tricky part here is to detect database backend specific capabilities and have a python equivalent fallback.
>>
>> Any thoughts?
>
>
> A couple of questions about this:
> - What should happen when you instantiate a new model with DB default, and show that model to the user in a form. Is the field shown to the user, and if so, what value should it have?
The field would have no value, so when displayed on the form it would be blank. A field with blank=False which is included in a form, having a db_default would be useless.
> - How to implement actual fetching of the values after save() - PostgreSQL supports RETURNING, but this is not the case for all databases.
The value would be fetched on demand on its first access, saving a trip to the database if the field is not accessed. Subsequent updates on that instance would leave out that field from the list of fields to be updated, unless its value has been changed on the instance. Maybe we can allow to handle this based on some parameter provided to save() ?
> - When is the default applied? On first save of the model, or on model init time?
Of course on first save, as we want the default value atomically within the same transaction.
> - Do we want to allow extending this to defaults that are applied on every save (automatic database backed modified timestamps for example)?
+1 for this one too.
>
> - Anssi
>
> --
> 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 django-develop...@googlegroups.com.
> To post to this group, send email to django-d...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-developers.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/f1a7cc68-de1a-49f8-bdf8-ebfaade59955%40googlegroups.com.
> - Do we want to allow extending this to defaults that are applied on every save (automatic database backed modified timestamps for example)?
+1 for this one too.
Hi Owais,
I did not have the time to start any work on this. I'm very much interested in this and I'd be happy to contribute to this in any way. I'm following along on the other thread you started [1].
--
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 django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
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/9fd48e92-d35f-4fea-9f27-95b91db895af%40googlegroups.com.
Yeah seems like `db_default` was the felling, at least last time I scanned through this long-going discussion :DI've had to tweak Django's migration handling a bit to handle our zero-downtime requirements.