Django 1.7迁移添加原始查询以设置auto_increment初始值 [英] Django 1.7 migration to add raw query to set auto_increment initial value

查看:131
本文介绍了Django 1.7迁移添加原始查询以设置auto_increment初始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django v1.7,我需要将初始的自动增量值设置为1000000,我找不到任何Django文档,显示有这样的功能,而且我有很多这样的功能的依赖关系,所以创建一个带有指定键的虚拟记录并不容易,然后删除它。



所以唯一合理的方法是把 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆