| 1 | | The migration generated for this contains removing the old pk and adding new pk : |
| 2 | | {{{ |
| 3 | | class Migration(migrations.Migration): |
| 4 | | |
| 5 | | dependencies = [ |
| 6 | | ("ticket_34151", "0001_initial"), |
| 7 | | ] |
| 8 | | |
| 9 | | operations = [ |
| 10 | | migrations.RemoveField( |
| 11 | | model_name="place", |
| 12 | | name="id", |
| 13 | | ), |
| 14 | | migrations.RemoveField( |
| 15 | | model_name="storechain", |
| 16 | | name="id", |
| 17 | | ), |
| 18 | | migrations.AddField( |
| 19 | | model_name="place", |
| 20 | | name="uid", |
| 21 | | field=models.UUIDField( |
| 22 | | default=uuid.uuid4, |
| 23 | | editable=False, |
| 24 | | primary_key=True, |
| 25 | | serialize=False, |
| 26 | | unique=True, |
| 27 | | ), |
| 28 | | ), |
| 29 | | migrations.AddField( |
| 30 | | model_name="storechain", |
| 31 | | name="uid", |
| 32 | | field=models.UUIDField( |
| 33 | | default=uuid.uuid4, |
| 34 | | editable=False, |
| 35 | | primary_key=True, |
| 36 | | serialize=False, |
| 37 | | unique=True, |
| 38 | | ), |
| 39 | | ), |
| 40 | | ] |
| 41 | | }}} |
| 42 | | but on some databases (mysql, postgres) we cannot delete a pk of a model which is referenced by other. |
| 43 | | I tried to implement a solution([https://github.com/django/django/pull/16325 draft PR] ) which is working fine for sqlite3 but throws the following error on some dbs (mysql, postgres) during the RemoveField operation: |
| 44 | | {{{ |
| 45 | | (1829, "Cannot drop column 'id': needed in a foreign key constraint 'ticket_34151_storech_placespk_id_ca7ce831_fk_ticket_34' of table 'ticket_34151_storechain'") |
| 46 | | }}} |
| 47 | | This made me think if it is really possible to add a new pk to a referenced model for dbs like mysql and postgres? |
| | 1 | I tried to implement a solution in a [https://github.com/django/django/pull/16325 draft PR] . Any input is appreciable. |