mysql - pk 作为绝对 id 有效吗? ( Django )

标签 mysql django uuid

删除最后一个模型后,将创建的下一个模型将被分配已删除的模型 pk,这意味着指向已删除模型的任何链接现在都将指向新模型。

那么我们应该使用 PK 还是创建 UUID? 例如用户配置文件,某些高级配置文件在删除后将指向一些全新的配置文件。

  • 这个网站,stack-overflow 使用 PK 来提问,我想知道我写的内容是否也适用于这里

最佳答案

从最简单的意义上来说,数据库使用 PK 字段的计数器,并在添加新记录时递增该计数器。删除/更新操作不会修改计数器。所以数据库不可能两次使用相同的值。

编辑:哎呀,这似乎是 Sqlite 的一个功能。详细信息在这里:http://sqlite.org/autoinc.html

引用文档:

If no ROWID is specified on the insert, or if the specified ROWID has a value of NULL, then an appropriate ROWID is created automatically. The usual algorithm is to give the newly created row a ROWID that is one larger than the largest ROWID in the table prior to the insert.

还有:

The normal ROWID selection algorithm described above will generate monotonically increasing unique ROWIDs as long as you never use the maximum ROWID value and you never delete the entry in the table with the largest ROWID.

关于mysql - pk 作为绝对 id 有效吗? ( Django ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9699811/

相关文章:

java - randomUUID 是否提供唯一 ID?

php - FullCalendar,JSON 数组为空但正在处理 PHP 文件

python - 在 Django Web 项目中,我的应用程序无法识别

python - ImproperlyConfigured : SQLite 3. 需要 8.3 或更高版本(发现 3.7.17)

python - python 中的 Cron 解析器和验证

java - 创建带零的 UUID

java - 从字符串中过滤掉 UUId 编号

mysql |显示具有 2 个条件的数据

mysql - 如何查询blob数据

php - 在 PHP 中为 MATCH AGAINST 准备的语句不起作用