#35763: Setting the auto increment value of a database model breaks when you 
add a
new field to the model
-------------------------------------+-------------------------------------
     Reporter:  Kevin Renskers       |                    Owner:  Sachin
                                     |  Kundalwal
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  5.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

 * resolution:   => invalid
 * status:  assigned => closed

Comment:

 Hello Kevin, thank you for your report.

 It's unclear that this qualifies as a bug report for Django. This may be
 better suited to be a support request: the best place to get answers to
 your issue is using any of the user support channels from
 [https://docs.djangoproject.com/en/dev/faq/help/#how-do-i-do-x-why-
 doesn-t-y-work-where-can-i-go-to-get-help this link].

 I did some research nevertheless because I was curious, and I found out a
 solution that works. I followed
 [https://stackoverflow.com/questions/117800/how-to-get-django-autofields-
 to-start-at-a-higher-number this post] and added to the initial migration
 this code:
 {{{#!python
 def set_counter(apps, schema_editor):
     Content = apps.get_model("ticket_35763", "Content")
     db_alias = schema_editor.connection.alias
     Content.objects.using(db_alias).create(id=50000, name="Initial
 content.")

 # ...

         migrations.RunPython(set_counter, None),
 }}}
 With the above, all future `Content` insertions, even after new
 migrations, use the correct value.

 So, since the goal of this issue tracker is to track issues about Django
 itself, and your issue seems, at first, to be located in your custom code,
 I'll be closing this ticket as invalid following the
 [https://docs.djangoproject.com/en/dev/internals/contributing/triaging-
 tickets/#closing-tickets ticket triaging process]. If, after debugging,
 you find out that this is indeed a bug in Django, please re-open with the
 specific details and please be sure to include a small Django project to
 reproduce or a failing test case.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35763#comment:3>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107019201858d2e-ab8575cc-861d-459f-b2e9-3ff67c382337-000000%40eu-central-1.amazonses.com.

Reply via email to