Diesel error message Actix

Hello,

Im following this tutorial on Windows : https://dev.to/open-graphql/building-powerful-graphql-servers-with-rust-3gla

but as soon as I do this :

diesel migration run
The --database-url argument must be passed, or the DATABASE_URL environment variable must be set.

and I have a env. file with this as contents :

DATABASE_URL=postgres://localhost/rust_graphql_exampl

What went wrong or what am I doing wrong here ?

Roelof

Are you calling the dotenv function to make sure the file is loaded?

No, I did only the steps mentioned in the tutorial
so these :

cargo install diesel_cli --no-default-features --features postgres
echo DATABASE_URL=postgres://localhost/rust_graphql_example > .env
diesel setup
diesel migration generate create_members
diesel migration run

nobody a idea ?

You need to use dotenv before you use DATABASE_URL. From the tutorial you linked, they use it here:

fn establish_connection() -> PgConnection {
  dotenv().ok();
  let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
  PgConnection::establish(&database_url).expect(&format!("Error connecting to {}", database_url))
}

you can't directly use variables from .env. they need to be loaded in at first, like alice showed by calling dotenv().ok();

it has to be used somewhere before you used an env variable. I usually make it the first line in my main()

also you said env. file, not sure if that's a typo but it's supposed to be called .env

I see that the tutorial does that later.
For now I can do diesel setup --database_url = "postgres://localhost/rust_graphql_example"
as the error message says.

Can the problem not be that Diesel is not working fine with Windows ?

did this work?
If this worked but the env variable version didn't, the issue with your env variable loading.

yep, it worked

diesel setup --database-url "postgres://localhost/rust_graphql_example"
Creating database: rust_graphql_example
fe_sendauth: no password supplied

but this does not run :

diesel migration run  --database-url "postgres://localhost/rust_graphql_example" 
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ConnectionError(BadConnection("fe_sendauth: no password supplied\n"))', C:\Users\rwobb\.cargo\registry\src\github.com-1ecc6299db9ec823\diesel_cli-1.4.1\src/main.rs:83:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I checked but the database is not made.
So I think this tutorial is or forgetting to mention things or assume that you know how to set up a database with diesel.

fe_sendauth: no password supplied

Your error message indicates that the provided credentials for postgres are not valid. Please recheck the configuration of your database server.

So I think this tutorial is or forgetting to mention things or assume that you know how to set up a database with diesel.

That's not specific to diesel, but part of the general setup of a database server. If you haven't done something like this before maybe check the corresponding guides provided by postgresql.
Also this is definitively nothing that should be covered by the guides provided by diesel as this touches the database itself. The configuration there is highly depended on your specific environment, so diesel would not be able to cover all possible variants.

not to mention postgres setup is not exactly intuitive.

If you follow this argumentation down to the bottom where would you stop mentioning setup related stuff? Should the guide include a part describing how to setup your operating system? Or even how to assemble your own PC? I mean if you want to use postgres (which is not the only choice while using diesel) you need to setup postgres in a meaningful way. I think it should be obvious that the postgres docs are a more appropriated location for documentation related to that topic than the diesel documentation.

I think you misunderstood. I was trying to say that postgres' setup process isn't very straightforward so they can't just include it in the tutorial. I was agreeing with you.