Django 1.7迁移添加原始查询以设置auto_increment初始值 [英] Django 1.7 migration to add raw query to set auto_increment initial value
问题描述
所以唯一合理的方法是把 alter table tablename auto_increment = 1000000
在初始迁移文件中,但我也找不到一个方法在这个文档
问题是如何在新的迁移系统中执行此操作?
甜蜜,发现这个文档
只需在操作数组中添加
operations = [
migrations.CreateModel(...) ,
#mysql具体
migrations.RunSQL('alter table tablename auto_increment = 1000000'),
]
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?
Sweet, found this documentation
Just add this in the operations array
operations = [
migrations.CreateModel(...),
# mysql specific
migrations.RunSQL('alter table tablename auto_increment=1000000'),
]
这篇关于Django 1.7迁移添加原始查询以设置auto_increment初始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!