* Attachment "0001_initial.py" added.
--
Ticket URL: <https://code.djangoproject.com/ticket/33932>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "0002_rename_id_son_base_ptr.py" added.
* Attachment "0003_alter_son_base_ptr.py" added.
Comment (by Benoît Vinot Roseau Technologies):
I have attached the three migrations files of the small example but you
were too fast for me...
It would be my first contribution...
--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:3>
Comment (by Mariusz Felisiak):
Can you confirm [https://code.djangoproject.com/ticket/33932#comment:2 the
diff] works for you?
--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:4>
Comment (by Benoît Vinot Roseau Technologies):
I confirm it works
--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:5>
Comment (by Mariusz Felisiak):
Great!, I created a regression test inspired by your migrations:
{{#!diff
+ def test_autofield_to_o2o(self):
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ editor.create_model(Note)
+
+ # Rename the field.
+ old_field = Author._meta.get_field("id")
+ new_field = AutoField(primary_key=True)
+ new_field.set_attributes_from_name("note_ptr")
+ with connection.schema_editor() as editor:
+ editor.alter_field(Author, old_field, new_field, strict=True)
+ # Alter AutoField to OneToOneField.
+ new_field_o2o = OneToOneField(Note, CASCADE)
+ new_field_o2o.set_attributes_from_name("note_ptr")
+ with connection.schema_editor() as editor:
+ editor.alter_field(Author, new_field, new_field_o2o,
strict=True)
+ columns = self.column_classes(Author)
+ field_type, _ = columns["note_ptr_id"]
+ self.assertEqual(
+ field_type,
connection.features.introspected_field_types["IntegerField"]
+ )
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:6>
Comment (by Mariusz Felisiak):
Replying to [comment:3 Benoît Vinot Roseau Technologies]:
> It would be my first contribution... I can start a PR on GitHub
Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:7>
* owner: nobody => Benoît Vinot Roseau Technologies
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:8>
Comment (by Benoît Vinot Roseau Technologies):
I have created a PR here with your test and your solution.
https://github.com/django/django/pull/15964
--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:9>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:10>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:11>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"e3cb8bcb7d2a2d392e726ee1f7e32a8d9038e14c" e3cb8bc]:
{{{
#!CommitTicketReference repository=""
revision="e3cb8bcb7d2a2d392e726ee1f7e32a8d9038e14c"
Fixed #33932 -- Fixed altering AutoFields to OneToOneField on PostgreSQL.
Regression in 2eea361eff58dd98c409c5227064b901f41bd0d6.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:12>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"85942cf6692f44d11d6d574b2429d201cc1e0aa7" 85942cf6]:
{{{
#!CommitTicketReference repository=""
revision="85942cf6692f44d11d6d574b2429d201cc1e0aa7"
[4.1.x] Fixed #33932 -- Fixed altering AutoFields to OneToOneField on
PostgreSQL.
Regression in 2eea361eff58dd98c409c5227064b901f41bd0d6.
Backport of e3cb8bcb7d2a2d392e726ee1f7e32a8d9038e14c from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:13>