'error: Column `article_content` cannot be named the same as its table [closed]
I am using this command to generate model using diesel_ext:
diesel_ext --schema-file src/model/diesel/dolphin/dolphin_schema.rs --model
When I using cargo build to compile the project. It shows an error like this:
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
What should I do to config to add the #[sql_name = "article_content"] comment before the column? I could not found any tips from the document. I tried to add comment like this:
table! {
article_content (id) {
id -> Int8,
article_id -> Int8,
#[sql_name = "article_content"]
article_content -> Varchar,
}
}
still did not fix this problem. More import, I was wonder is it possible to make diesel support with the table column name could be the same with the table name, so that I did not change anything. Is it possible?
Solution 1:[1]
Tweak the code like this would fixed this problem:
table! {
article_content (id) {
id -> Int8,
article_id -> Int8,
#[sql_name = "article_content"]
articleContent -> Varchar,
}
}
It will map the colum articleContent to database article_content. I have to tweak this code every time after using script auto generate, that's the difficult way to tweak every time.
Solution 2:[2]
There is an example here in the documentation of the table! macro.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dolphin |
| Solution 2 | weiznich |
