【问题标题】:Diesel cli '`database.sqlite3` is not a valid database URL. It should start with `postgres://`'Diesel cli '`database.sqlite3` 不是有效的数据库 URL。它应该以 `postgres://`' 开头
【发布时间】:2022-01-26 23:43:06
【问题描述】:

在 ENV 中具有 sqlite 数据库的项目上运行 diesel migration run 时,我收到此错误,提示它不是有效的 postgres url。

$ diesel migration run
thread 'main' panicked at '`database.sqlite3` is not a valid database URL. It should start with `postgres://`',

来自项目的 Cargo.toml

[package]
name = "matrix_bot"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
diesel = { version = "1.4.4", features = ["sqlite"] }
dotenv = "0.15.0"
tokio = {version = "1.14.0", features = ["full"]}
matrix-sdk = "0.4.1"

.env 内容

DATABASE_URL=database.sqlite3

【问题讨论】:

  • 您没有包含任何代码或Cargo.toml 来显示您的配置,因此无法看到实际问题。

标签: rust rust-diesel


【解决方案1】:

如果安装diesel_cli 时启用了postgres 功能,它将不再适用于sqlite 数据库。解决办法是通过cargo重新安装cli

cargo install diesel_cli --no-default-features

【讨论】:

  • 这是不正确的。您不必安装禁用默认功能的 CLI 即可使用 SQLite。您的代码或Cargo.toml 中可能还有其他问题,但您没有包含这些问题,因此您的问题没有帮助。
  • @Herohtar 更新为包含 cargo.toml。我观察到这工作得非常好,然后我在一个使用 postgres 的单独项目/目录中进行了演示。当我回到我现有的项目时,我无法运行 cli,直到按照描述重新安装它。
  • 唯一改变它给出上述错误并且它运行正确的是货物安装。
  • 这是缺少的关键细节——不是代码错误,而是您之前安装的 CLIpostgres 功能。除非启用了使用该数据库类型的功能,否则 Diesel 显然无法使用特定数据库。
  • 您应该只运行cargo install diesel_cli 以包含所有功能,那么您不会有任何问题。但是,这需要所有三个数据库(PostgreSQL、MySQL 和 SQLite)的依赖项,因此如果您不需要 MySQL 并且不想安装该依赖项,则可以运行 cargo install diesel_cli --no-default-features --features "postgres sqlite"。这将允许你的两个项目编译。
猜你喜欢
  • 1970-01-01
  • 2022-12-10
  • 2013-07-26
  • 1970-01-01
  • 1970-01-01
  • 2019-09-19
  • 2019-11-24
  • 2017-08-20
  • 2011-11-07
相关资源
最近更新 更多