Diesel on windows is not reading .env

I am following the getting started with diesel and I can not seem to fix this error even though I have the .env with DATABASE_URL = postgres://postgres:Jordago99!@localhost:5432/example
diesel setup
The --database-url argument must be passed, or the DATABASE_URL environment variable must be set

if I pass it as diesel setup --database-url postgres://postgres:Jordago99!@localhost:5432/example then it will work

Is the .env file in the same directory you're running the CLI from?

I just tried it and it worked fine. I don't typically develop on Windows, so I installed chocolatey, postgresql and diesel-cli, copied your .env file to a blank project and ran diesel setup with no issues (except that it can't connect to the server, but it reads the DATABASE_URL variable correctly). If I try to do it in another directory where I have no .env file, my output is a little different

PS C:\Users\Usr\Dev> diesel setup
Creating migrations directory at: C:\Users\Usr\Dev\migrations
The --database-url argument must be passed, or the DATABASE_URL environment variable must be set.

which makes me think you might be using an old version of diesel-cli. If that's the case, updating it could help?

PS C:\Users\Usr\Dev> diesel --version
diesel 2.0.1
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.