# Migrating ID fields to BigAutoField

**URL:** <https://forum.djangoproject.com/t/migrating-id-fields-to-bigautofield/7861>\
**Category:** Using Django\
**Created:** [May 10, 2021, 4:07pm UTC](https://forum.djangoproject.com/t/migrating-id-fields-to-bigautofield/7861 "2021-05-10T16:07:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew-hodgins](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/matthew-hodgins/32/4493_2.png) [@matthew-hodgins](https://forum.djangoproject.com/u/matthew-hodgins)\
**Post date:** [May 10, 2021, 4:07pm UTC](https://forum.djangoproject.com/t/migrating-id-fields-to-bigautofield/7861/1 "2021-05-10T16:07:42Z")

</div>

Django version: 3.2  
DB: MySQL

My application was built with an old version of Django, so the auto-generated ID field is a 32-bit integer. I’d like to future proof this by moving to 64-bit. I’ve set:

`DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'`

in my settings file and created the auto-generated migration files. This seemed to work but when I applied the migrations, it did not handle foreign key relationships correctly. The ID field on the original model was set to a 64-bit integer but the `ForeignKey` field in the other was still a 32-bit integer (and a few times, vice versa). The migration then failed and I was unable to rollback without restoring from a backup.

Is anyone aware of any documentation or best practices for ensuring these DB migrations are successful?
