【问题标题】:error: Column `article_content` cannot be named the same as its table [closed]错误:列“article_content”不能与其表命名相同[关闭]
【发布时间】:2022-01-23 01:16:50
【问题描述】:

当我使用此命令生成模型时,使用diesel_ext:

diesel_ext --schema-file src/model/diesel/dolphin/dolphin_schema.rs --model

它显示如下错误:

error: Column `article_content` cannot be named the same as its table.
 You may use `#[sql_name = "article_content"]` to reference the table's `article_content` column.
 See the documentation of the `table!` macro for details`

  --> src/model/diesel/dolphin/dolphin_schema.rs:37:1
   |
37 | / table! {
38 | |     article_content (id) {
39 | |         id -> Int8,
40 | |         article_id -> Int8,
41 | |         article_content -> Varchar,
42 | |     }
43 | | }
   | |_^
   |
   = note: this error originates in the macro `__static_cond` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `reddwarf-admin` due to previous error

我应该如何配置在列前添加#[sql_name = "article_content"] 注释?我无法从文档中找到任何提示。我试图添加这样的评论:

table! {
    article_content (id) {
        id -> Int8,
        article_id -> Int8,
        #[sql_name = "article_content"]
        article_content -> Varchar,
    }
}

仍然没有解决这个问题。

【问题讨论】:

    标签: rust rust-cargo rust-diesel


    【解决方案1】:

    table! 宏的文档中有一个示例。

    【讨论】:

      【解决方案2】:

      像这样调整代码可以解决这个问题:

      table! {
          article_content (id) {
              id -> Int8,
              article_id -> Int8,
              #[sql_name = "article_content"]
              articleContent -> Varchar,
          }
      }
      

      它将列articleContent 映射到数据库article_content。每次使用脚本自动生成后,我都必须调整这段代码,这是每次调整的困难方法。

      【讨论】:

        猜你喜欢
        • 2014-03-05
        • 2020-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-21
        • 2018-02-14
        • 1970-01-01
        相关资源
        最近更新 更多