migrations not created for foreign key when primary key type is changed

204 views
Skip to first unread message

Manasvi Dobariya

unread,
Sep 2, 2022, 9:15:11 AM9/2/22
to Django users
I have default primary key in the model which is being referenced as foreign key in another model. Now, when I change this primary key type from AutoField to BigAutoField, migrations for only primary keys are being generated no migration for foreign key is generated. However, when I apply the migration generated for primary key, foreign key type also gets changed from int to bigint in postgres database. Is it expected that migrations for foreign key will not get generated?

Devang

unread,
Sep 2, 2022, 11:55:21 PM9/2/22
to django...@googlegroups.com
I guess it might be changed by postgres. Have you checked postgres documentation ? 

On Fri, 2 Sep 2022, 18:45 Manasvi Dobariya, <man...@awaaz.de> wrote:
I have default primary key in the model which is being referenced as foreign key in another model. Now, when I change this primary key type from AutoField to BigAutoField, migrations for only primary keys are being generated no migration for foreign key is generated. However, when I apply the migration generated for primary key, foreign key type also gets changed from int to bigint in postgres database. Is it expected that migrations for foreign key will not get generated?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a4cbdf90-bd62-46a7-9657-1c7ba39509c2n%40googlegroups.com.

Markus Holtermann

unread,
Sep 3, 2022, 4:32:24 AM9/3/22
to Django Users
This is expected and by design. Because in the model where you define the foreign key, you also don't define its type. The type is automatically resolved through the column type from the target model.

Cheers
Markus 

On Fri, Sep 2, 2022, at 10:39 AM, Manasvi Dobariya wrote:
I have default primary key in the model which is being referenced as foreign key in another model. Now, when I change this primary key type from AutoField to BigAutoField, migrations for only primary keys are being generated no migration for foreign key is generated. However, when I apply the migration generated for primary key, foreign key type also gets changed from int to bigint in postgres database. Is it expected that migrations for foreign key will not get generated?


Devang

unread,
Sep 3, 2022, 8:40:36 AM9/3/22
to django...@googlegroups.com
Hi Markus, I was thinking same. 

Reply all
Reply to author
Forward
0 new messages