Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.7 migration to add raw query to set auto_increment initial value

Tags:

django

I am using Django v1.7 and I need to set the initial auto increment value to something like 1000000, I couldn't find any Django docs that shows there is a feature like this, and the model I have have a lot of dependencies, so it's not easy to create a dummy record with key specified and then delete it.

So the only sensible way I think is to put alter table tablename auto_increment=1000000 in the initial migration file, but I also cannot find a way in this documentation

The question is how do I do that in the new migration system?

like image 363
James Lin Avatar asked Aug 14 '14 22:08

James Lin


1 Answers

Sweet, found this documentation

Just add this in the operations array

operations = [
    migrations.CreateModel(...),
    # mysql specific
    migrations.RunSQL('alter table tablename auto_increment=1000000'),
]
like image 158
James Lin Avatar answered Nov 15 '22 07:11

James Lin