< 返回版块

dongdong 发表于 2019-07-04 14:24

Tags:diesel

我根据文档一步步操作 https://diesel.rs/guides/getting-started/

Typically the schema module isn't created by hand, it gets generated by Diesel. When we ran diesel setup, a file called diesel.toml was created which tells Diesel to maintain a file at src/schema.rs for us. The file should look like this

diesel.toml 文件是有了,但是我没搞懂 src/schema.rs 是怎么生成的

再运行,那么就报错了

error[E0583]: file not found for module `schema`
 --> src/lib.rs:1:9
  |
1 | pub mod schema;
  |         ^^^^^^
  |
  = help: name the file either schema.rs or schema/mod.rs inside the directory "src"

error: aborting due to previous error

For more information about this error, try `rustc --explain E0583`.
error: Could not compile `diesel_demo`.

是我哪里遗漏了什么吗...

环境: cargo 1.36.0-nightly (6be12653d 2019-04-19)

评论区

写评论
sunheartGH 2019-07-05 11:49

对以下内容的回复:

如果数据库表都存在,或新增/修改了字段,运行 diesel migration run 的时候会自动将数据库表映射到schema.rs文件中

Ryan-Git 2019-07-04 15:25

diesel print-schema does exactly that

对以下内容的回复:

作者 dongdong 2019-07-04 15:13

额,运行 diesel migration run 生成了

但是有个疑问,它执行了 up.sql 的脚本初始化了数据库

然后生成了 schema.rs 要是数据库表都存在,不需要创建表,那schema.rs要怎么单独生成呢

1 共 3 条评论, 1 页