Django型号ID有差距 [英] Django model id has gaps

查看:51
本文介绍了Django型号ID有差距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在多个应用程序服务器上运行的Django 1.7rc项目和一个MySQL.

I am have a Django 1.7rc project running on multiple app servers and a MySQL.

我注意到模型的主键存在间隙,例如,从10001跳到10003,从10011跳到10014.我不知道为什么,没有代码可以直接删除记录,但是可以级联删除,我将作进一步调查.

I have noticed the primary key of a model has gaps, eg, from 10001 jumps to 10003, 10011 jumps to 10014. I cannot figure out why, there is no code to delete the records directly, however it could be cascade deleted, which I will investigate further.

    order = Order(cart=cart)
    order.billing_address = billing_address
    order.payment = payment
    order.account = account
    order.user_uuid = account.get('uuid')
    order.save()

我想问一下这在多应用服务器设置上是否正常?

Thought I would ask here if this is normal on a multiple app server setup?

推荐答案

主键中的间隙是正常的(除非您使用的是配置错误的SQLite表,默认情况下它不使用单调PK)并有助于维护引用正直.话虽如此,它们通常仅是由表内的删除或更新(级联或其他方式)引起的.确认您没有可直接或间接删除或更新该表中PK的代码.

Gaps in a primary key are normal (unless you're using a misconfigured SQLite table, which does not use a monotonic PK by default) and help to maintain referential integrity. Having said that, they are usually only caused by deletions or updates within the table, cascaded or otherwise. Verify that you have no code which may delete or update the PK in that table, directly or indirectly.

这篇关于Django型号ID有差距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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