Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当主键名不为id的时候生成的代码有误 #64

Closed
heheda123123 opened this issue May 15, 2024 · 8 comments
Closed

当主键名不为id的时候生成的代码有误 #64

heheda123123 opened this issue May 15, 2024 · 8 comments

Comments

@heheda123123
Copy link

比如下面这个表,主键是comment_id
image
使用tortoise生成代码
可以看到代码里面还是用的id去查询
image
image
这里进行测试就会产生报错
image
image

@heheda123123
Copy link
Author

不过我看生成的代码是restful风格的,看怎么处理合适点呢
1 要么在生成的时候进行提示主键名不是id
2 要么就根据表里的主键名对生成的代码自动修改

@zy7y
Copy link
Owner

zy7y commented May 15, 2024

不过我看生成的代码是restful风格的,看怎么处理合适点呢 1 要么在生成的时候进行提示主键名不是id 2 要么就根据表里的主键名对生成的代码自动修改

查询详情的dao 获取主键,但这种属于表设计不规范吧(个人感觉),暂时由用户自行控制

@zy7y
Copy link
Owner

zy7y commented May 15, 2024

get_or_none(id=id),改成get_or_none(comment_id=id)

@heheda123123
Copy link
Author

不过我看生成的代码是restful风格的,看怎么处理合适点呢 1 要么在生成的时候进行提示主键名不是id 2 要么就根据表里的主键名对生成的代码自动修改

查询详情的dao 获取主键,但这种属于表设计不规范吧(个人感觉),暂时由用户自行控制

是随便找的其他项目的数据库,不是restful风格。不过这种也可以提示下把。

@zy7y
Copy link
Owner

zy7y commented May 15, 2024

使用fastapi中间件 处理服务上的问题,至于生成代码 给提示 短时间内不会支持

不过我看生成的代码是restful风格的,看怎么处理合适点呢 1 要么在生成的时候进行提示主键名不是id 2 要么就根据表里的主键名对生成的代码自动修改

查询详情的dao 获取主键,但这种属于表设计不规范吧(个人感觉),暂时由用户自行控制

是随便找的其他项目的数据库,不是restful风格。不过这种也可以提示下把。

@heheda123123
Copy link
Author

heheda123123 commented May 16, 2024

我的意思是类似这样弹个提示,提示使用者一下
image

@zy7y
Copy link
Owner

zy7y commented May 17, 2024

较繁琐,短期不会支持

@zy7y
Copy link
Owner

zy7y commented May 17, 2024

随v0.2.5发布;解决方案:dao层兼容非id为主键的情况;

DDL

CREATE TABLE `aerich` (
  `aerich_id` int NOT NULL AUTO_INCREMENT,
  `version` varchar(255) NOT NULL,
  `app` varchar(100) NOT NULL,
  `content` json NOT NULL,
  PRIMARY KEY (`aerich_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

修复方案

image

@zy7y zy7y closed this as completed in 198ee90 May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants