当我的密码包含 at 符号 (@) 时,如何指定 Diesel DATABASE_URL?
How do I specify a Diesel DATABASE_URL when my password contains an at-sign (@)?
我是按照他们的 official documentation 开始使用 Diesel 的。我还安装了 PostgreSQL。我的数据库用户名是 postgres
,密码是 1schoollife@
.
我从
开始
$ echo DATABASE_URL=postgres://postgres:1schoollife@@localhost/diesel_demo > .env
$ diesel setup
结果:
Creating migrations directory at: /home/naufil/Desktop/rust/3june/testing/migrations
Creating database: diesel_demo
database "diesel_demo" already exists
我创建了一个迁移:
$ diesel migration generate create_posts
Creating migrations/2019-06-03-182531_create_posts/up.sql
Creating migrations/2019-06-03-182531_create_posts/down.sql
迁移数据库时出现以下错误:
$ diesel migration run
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ConnectionError(BadConnection("could not translate host name \"@localhost\" to address: Name or service not known\n"))', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
您提供的 DATABASE_URL
不是您尝试使用的 URL。 @
是一个特殊字符,用于将凭据与主机名分开。由于您的凭据包含 @
,因此需要对其进行 URL 转义:
postgres://postgres:1schoollife%40@localhost/diesel_demo
柴油机保养师sgrif said:
Yes, percent encoding is 100% the correct thing for us to be doing.
这是在 PR 1058
中实现的
我是按照他们的 official documentation 开始使用 Diesel 的。我还安装了 PostgreSQL。我的数据库用户名是 postgres
,密码是 1schoollife@
.
我从
开始$ echo DATABASE_URL=postgres://postgres:1schoollife@@localhost/diesel_demo > .env
$ diesel setup
结果:
Creating migrations directory at: /home/naufil/Desktop/rust/3june/testing/migrations
Creating database: diesel_demo
database "diesel_demo" already exists
我创建了一个迁移:
$ diesel migration generate create_posts
Creating migrations/2019-06-03-182531_create_posts/up.sql
Creating migrations/2019-06-03-182531_create_posts/down.sql
迁移数据库时出现以下错误:
$ diesel migration run
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ConnectionError(BadConnection("could not translate host name \"@localhost\" to address: Name or service not known\n"))', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
您提供的 DATABASE_URL
不是您尝试使用的 URL。 @
是一个特殊字符,用于将凭据与主机名分开。由于您的凭据包含 @
,因此需要对其进行 URL 转义:
postgres://postgres:1schoollife%40@localhost/diesel_demo
柴油机保养师sgrif said:
Yes, percent encoding is 100% the correct thing for us to be doing.
这是在 PR 1058
中实现的