I'll forget it, so make a note for myself. There is AutoField in Django, but the clumn of the database created by it will be int.
I want to auto increment with bigint. There was a kind person on stackoverflow.
from django.db.models import fields
from south.modelsinspector import add_introspection_rules
class BigAutoField(fields.AutoField):
def db_type(self, connection):
if 'mysql' in connection.__class__.__module__:
return 'bigint AUTO_INCREMENT'
return super(BigAutoField, self).db_type(connection)
add_introspection_rules([], ["^MYAPP\.fields\.BigAutoField"])
For those who do not use south
from django.db.models import fields
class BigAutoField(fields.AutoField):
def db_type(self, connection):
if 'mysql' in connection.__class__.__module__:
return 'bigint AUTO_INCREMENT'
return super(BigAutoField, self).db_type(connection)
This seems to be fine.
First, prepare a test model One thing to note when using AutoIncrement is if it has been used in another field.
A model can't have more than one AutoField.
I get angry.
from django.db import models
class test(models.Model):
id = BigAutoField(primary_key=True)
python manage.py syncdb
It became auto_increment!
If you have any supplements or mistakes, please point them out.
reference: http://stackoverflow.com/questions/2672975/django-biginteger-auto-increment-field-as-primary-key