gpt4 book ai didi

rust - 柴油。火箭和火箭.rs : don't understand why it wants a databases table

转载 作者:行者123 更新时间:2023-12-03 11:34:48 27 4
gpt4 key购买 nike

我是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指示设置的方式...

编辑:固定错别字;
EDIT2:数据库本身看起来很好:
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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com