#35589: AlterField should raise an error when changing primary key
----------------------------------+--------------------------------------
     Reporter:  Csirmaz Bendegúz  |                    Owner:  (none)
         Type:  New feature       |                   Status:  closed
    Component:  Migrations        |                  Version:  dev
     Severity:  Normal            |               Resolution:  needsinfo
     Keywords:  primary key       |             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:   => needsinfo
 * status:  new => closed

Comment:

 Hello! Thank you for your ticket.

 I was about to accept based on Forum discussions
 ([https://forum.djangoproject.com/t/serialfields-yay-or-nay/32541 0],
 [https://forum.djangoproject.com/t/makemigrations-bug-or-not/4012 1]) and
 related tickets (#26404) but when I started a small project to confirm
 that `AlterField` doesn't do anything, I started getting errors and it
 seems like `AlterField` does do something.

 Specifically, when I changed a field in a model from `primary_key=True` to
 `primary_key=False`, the generated migration looks like this:
 {{{
     operations = [
         migrations.AddField(
             model_name="testmodel",
             name="id",
             field=models.BigAutoField(
                 auto_created=True,
                 default=0,
                 primary_key=True,
                 serialize=False,
                 verbose_name="ID",
             ),
             preserve_default=False,
         ),
         migrations.AlterField(
             model_name="testmodel",
             name="otherid",
             field=models.IntegerField(),
         ),
     ]
 }}}

 When applying this migration, it failed with:
 {{{
 django.db.utils.ProgrammingError: both default and identity specified for
 column "id" of table "testapp_testmodel"
 LINE 1: ...COLUMN "id" bigint DEFAULT 0 NOT NULL PRIMARY KEY GENERATED ...
 }}}

 What do you mean exactly with ''AlterField doesn't do anything''?
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35589#comment:1>
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/010701909e90111a-613e8eaa-5e04-4747-8757-385789b5ceac-000000%40eu-central-1.amazonses.com.

Reply via email to