@sgrif
If proper features are not enabled, error messages to not point to this being the issue.
Started project with one backend, switched to a different backend and forgot to change Cargo.toml.
If DATABASE_URL is for a database where feature is not enabled, there should at least be a warning about this.
help: message: Could not load table names from databasepostgresql://sammy:sam
my@localhost/diesel_demo: StringError("Failed to establish a database connection a
t postgresql://sammy:sammy@localhost/diesel_demo. Error: BadConnection(\"Unable to
open the database file\")")
Cargo.toml
[dependencies]
diesel = { version = "0.15.0", features = ["sqlite"] }
diesel_codegen = { version = "0.15.0", features = ["sqlite"] }
dotenv = "0.9.0"
.env
DATABASE_URL=postgres://username:password@localhost/diesel_demo > .env
To clarify, specifically I think we should be checking for the URL starting with mysql://, postgres:// or postgresql:// when those features are not enabled. I think we can safely assume that the user is not trying to connect to a SQLite database in that case.
Related: We should strip sqlite:// from the URL if it's present. I've had a couple people try that expecting it to work.
This just broke my mind for a while, as I changed computers and couldn't understand the error that diesel-cli was giving me. Trying to connect to a postgres db with only the sqlite feature enabled provides the following:
$ diesel migration run
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ConnectionError(BadConnection("Unable to open the database file"))', libcore/result.rs:945:5
So yeah, this is still less than ideal. :)
I literally just encountered this problem and went on for 2 days.... Glad I found this issue.
I'll take a look at implementing this
I literally just encountered this problem and went on for ~2 hours ... Glad I found this issue.
I fixed this for the diesel-cli part. Can someone point me towards where to look in the libraries themselves, to do the same sort of error handling?
@porglezomp I do not think that this applies to diesel itself because there you are using concrete connection types. I think it's kind of obvious that something is wrong if you are doing SqliteConnection::establish("postgres://something/something")
Most helpful comment
Related: We should strip
sqlite://from the URL if it's present. I've had a couple people try that expecting it to work.