gpt4 book ai didi

python - 在 web2py 中,我可以将现有命名字段指定为遗留数据库中的自动编号 ID 吗?

转载 作者:太空宇宙 更新时间:2023-11-03 14:34:45 24 4
gpt4 key购买 nike

我在现有的 MSSQL 数据库中有几十个表autonumber ID 主键,但没有名为“id”的主键。他们是而是命名为 PropertyID、ClientID 等。官方文档似乎建议将这些字段中的每一个重命名为“id”:

Legacy Databases

web2py can connect to legacy databases under some conditions:

  • Each table must have a unique auto-increment integer field called "id"
  • Records must be referenced exclusively using the "id" field.

If these conditions are not met, it is necessary to manually ALTER TABLE to conform them to these requirements, or they cannot be accessed by web2py.

This should not be thought of as a limitation, but rather, as one of the many ways web2py encourages you to follow good practices.

但是,这需要打破其他领域的数百个现有查询使用此数据库的应用程序。肯定有办法指定要使用的现有自动编号字段的名称,而不是'id'。

这似乎是 Django got it right的区域和 web2py got it horribly wrong .还是我只是错过了什么? 似乎我只是错过了什么......

最佳答案

该声明已过时。 web2py支持的三种情况:

  1. 一个表有一个名为“id”的自增字段(默认)
  2. 一个表有一个不叫'id'的自增字段,定义这个表

    db.define_table('name',Field('id_name','id'),...其他字段...)

  3. 一个表有不同的主键

    db.define_table('name',...fields..., primarykey=[....])

主键是字段名称列表。

选项 3 不适用于所有支持的数据库,但可以轻松扩展。我们只是没有收到太多要求,所以我们没有足够的测试人员来测试所有可能的选项。请将此讨论移至 web2py 邮件列表,我们很乐意为您提供更多帮助。

关于python - 在 web2py 中,我可以将现有命名字段指定为遗留数据库中的自动编号 ID 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3230504/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com