Migrating Django 1.7 to add a raw request to set the initial value to auto_increment

I am using Django v1.7 and I need to set the initial value of auto-increment to something like 1,000,000, I could not find any Django docs that show that there is such a function, and the model has a lot of dependencies, so it’s not easy create a dummy record with the specified key and then delete it.

So, the only reasonable way, in my opinion, is to put alter table tablename auto_increment=1000000 in the source migration file, but I also cannot find a way in this documentation

The question is how to do this in the new migration system?

+5
source share
1 answer

Sweet, found this documentation

Just add this to your operations array

 operations = [ migrations.CreateModel(...), # mysql specific migrations.RunSQL('alter table tablename auto_increment=1000000'), ] 
+7
source

Source: https://habr.com/ru/post/1200364/


All Articles