I like to use MS Access as a reporting/query tool using the same MySQL database as my Django project. MS Access is having problems with BigAutoFields. My project and app (already in a beta stage) uses models with BigInt. Is it possible to change BigAutoField to AutoField in this stage of the development? Or should I have done that at the start. Changing settings.py and migrate does not effect the ‘old’ models. In SQL Workbench I can also not change this giving an error.
AutoField is an IntegerField, Values from 1
to 2147483647
are safe in all databases supported by Django, Model field reference | Django documentation | Django
and BigAutoField is a 64-bit integer, much like an AutoField except that it is guaranteed to fit numbers from 1
to 9223372036854775807
Model field reference | Django documentation | Django.
So if your data which is stored in database for that particular table’s field comes in the range of AutoField than it’s ok.
If you are getting error or something share it’s traceback.
Thanks for your reply. Can you explain how to change the BigAutoField to AutoField in Django. Just changing the settings.py does not effect the current models.
In MySQL Workbench I get this error:
You may need to add an explicit id
field in your models defined as AutoField(primary_key=True)
, then run makemigrations
and migrate
. I’m not sure if MySQL will handle that properly, but it’s worth a try on a test database.
Once that’s done, and you’ve made the settings change for DEFAULT_AUTO_FIELD
, you may then be able to remove those explicit field definitions - again followed by a makemigrations
and migrate
.
I found out that even if AutoField is set in settings.py a new model still uses BigAutoField if it has dependencies with other models still using BigAutoField. Because that’s the case I just stick with my current BigAutoField setting. I will look for other reporting tools and maybe build a Django App to do that.
Thanks all for your concern.