作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是Rust的新手,但遇到一个我无法解决的问题。
我的Cargo.toml
看起来像这样:
[dependencies]
rocket = "0.4.6"
rocket_codegen = "0.4.6"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
[dependencies.diesel]
version = "1.0.0"
default-features = false
features = ["sqlite"]
[dependencies.rocket_contrib]
version = "0.4.6"
default-features = false
features = ["diesel_sqlite_pool"]
[global.databases.urls_db]
url = "urls.sqlite"
我在
main.rs
上有这样的连接:
use rocket_contrib::databases::diesel;
#[database("urls_db")]
struct UrlsDbConn(diesel::SqliteConnection);
根据
urls
,我仅有的一张表叫做
schema.rs
:
table! {
urls (id) {
id -> Text,
uri -> Text,
}
}
但是当我尝试
cargo run
时,我得到了:
Error: Database configuration failure: 'urls_db'
=> Error: A table named `databases` was not found for this configuration
知道为什么吗?
databases
(复数)字符串在
Cargo.toml
(
global.databases.urls_db
)上,这是rocket.rs指示设置的方式...
main: /Users/carlos/Developer/caarlos0/beckerly/beckerly/urls.sqlite
sqlite> .tables
__diesel_schema_migrations urls
sqlite> select * from urls;
sqlite> insert into urls(id, uri) values ('g', 'https://google.com');
sqlite> select * from urls;
g|https://google.com
sqlite>
最佳答案
数据库配置应位于Rocket.toml
文件中:
[global.databases]
urls_db = { url = "urls.sqlite" }
该文档明确指出:
Then, in Rocket.toml or the equivalent via environment variables, configure the URL for the database in the databases table:
关于rust - 柴油。火箭和火箭.rs : don't understand why it wants a databases table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65666740/
我是一名优秀的程序员,十分优秀!