#24042: Custom AutoField fields do not work correctly on postgres
-------------------------------------+-------------------------------------
     Reporter:  Lucas Wiman          |                    Owner:  nobody
         Type:  New feature          |                   Status:  closed
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  fixed
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by felixxm):

 Tests from [https://github.com/django/django/pull/3776 PR] works for me
 when I will declare `db_returning = True` in `CustomDbGeneratedField`,
 e.g.
 {{{
 class Default(Func):
     template = 'DEFAULT'


 class CustomDbGeneratedField(models.Field):
     db_returning = True
     empty_strings_allowed = False

     def __init__(self, *args, **kwargs):
         kwargs.setdefault('default', Default)
         super().__init__(*args, **kwargs)

     def db_type(self, connection):
         if connection.vendor == 'mysql':
             return 'integer AUTO_INCREMENT'
         elif connection.vendor == 'postgresql':
             return 'serial'
         else:
             return 'integer'

     def get_internal_type(self):
         return "NotAutoField"
 }}}
 `db_returning` is still a private API but it's feasible to create a custom
 generated field.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/24042#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.94b3537014172ae8180c883407d74764%40djangoproject.com.

Reply via email to