Title
m

Max

06/14/2020, 8:02 PM
i setup a simple docker-compose file for just a prisma2 project, when i run it in the logs I get:
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
when i run
dk exec <c_name> npx prisma generate
it says it's ready to use, then I attempt to
dk exec <c_name> npx prisma introspect
and I get
`Can't reach database server at `postgres`:`5432
I can confirm the db is working and that without docker the introspection works, ive a volume setup which connects the docker container app folder and the local one, when I change the
prisma/.env
url string to something else and
cat
to ensure it has changed it works but when I run
introspect
in the container again it says that it cannot connect with the default
5432
port even though I changed it
j

janpio

06/14/2020, 8:06 PM
Is this the full output you get from
introspect
?
What is you db connection string?
(inside docker)
m

Max

06/14/2020, 8:08 PM
DATABASE_URL="<postgresql://user@localhost:5432/db>"

---

# docker exec <c_name> npx prisma introspect

Environment variables loaded from ./prisma/.env

Introspecting based on datasource defined in prisma/schema.prisma ā€¦
Error: P1001

Can't reach database server at `postgres`:`5432`

Please make sure your database server is running at `postgres`:`5432`.
I am able to connect to the postgres db through tableplus as well as the same project when running locally without docker
(postgres is dockerized too)
it makes no sense to me that running
introspect
in the container after changing the port in
prisma/.env
results in the same error with the same port even though it's changed which leads me to believe it may be prisma's fault
j

janpio

06/14/2020, 8:13 PM
That part was used quite a lot of times already, so I would be surprised šŸ™‚
Give me a min to check sth
Hm, the Postgres error message indeed only includes the host and port - not the full connection string.
But editing the port also changes it in my error message.
m

Max

06/14/2020, 8:16 PM
it does not for me, let me try once again to make sure
āÆ dkex back cat prisma/.env
DATABASE_URL="<postgresql://user:secret@localhost:2000/db>"
āÆ dkex back npx prisma introspect
Can't reach database server at `postgres`:`5432`
not quite sure why im getting the initial error on first start of the containers too in my op
j

janpio

06/14/2020, 8:25 PM
Is that the full output?
There should be more, like in the snippet above.
m

Max

06/14/2020, 8:25 PM
it is the same as above
1:1
j

janpio

06/14/2020, 8:25 PM
Ok, so you copied a modified version here?
Strange - as if it reads the file directly in the command, there is really no way how it could get the wrong information really.
Can you check if
DATABASE_URL
is set manually somehow maybe? (not that it should influence that)
m

Max

06/14/2020, 8:28 PM
šŸ˜…
I had an environment variable in my docker-compose file with a wrong password
DATABASE_URL
it was taking it from there
j

janpio

06/14/2020, 8:29 PM
Ha!
šŸš€
m

Max

06/14/2020, 8:29 PM
thank you so much for the help and im sorry for wasting ur time lmao, ur a gem
ā¤ļø 1
j

janpio

06/14/2020, 8:29 PM
Still strange that it was using that one, although it said it used the file...
m

Max

06/14/2020, 8:30 PM
yea i was a bit naive to not question that
j

janpio

06/14/2020, 8:30 PM
I would have expected the local file to overwrite the value set in the environment.
m

Max

06/14/2020, 8:30 PM
same!
i dont want to say how long I spent trying to figure this out
šŸ˜…
by the way to clarify something related, if I set the db_url in the
.env
which is in the root of my project managed by
dotenv
dep. which would take precedence (could I omit the
prisma/.env
file entirely in that scenario)
j

janpio

06/14/2020, 8:32 PM
But I can confirm that behavior and will open a bug issue.
m

Max

06/14/2020, 8:33 PM
much appreciated!
j

janpio

06/14/2020, 8:33 PM
Yes,
prisma/.env
is just a default location we read by convention.
You can create the env var whatever way you want.
m

Max

06/14/2020, 8:33 PM
šŸ‘
m

Max

06/14/2020, 9:53 PM
I think a bit more verbose errors would be quite nice when unable to connect to the database because I just ran into the same exact issue, however, this time I'm quite certain that the env var is not being overwritten by anything as it recognizes the changes
and yet I am getting the same exact error despite both containers being on the same network, can connect to each other, url string is correct etc. and its likely something simple im missing again hah
j

janpio

06/14/2020, 10:34 PM
Hm, but what could a better error message be?
r

Richard Ward

06/15/2020, 4:19 PM
@Max what you can do for the
.env
file is use your general one in your root, put the DB connection string in there and then:
cd prisma
ln -s ../.env
That will create a link
prisma/.env
which links to your project
.env
m

Max

06/15/2020, 10:52 PM
@Richard Ward good thinking, thanks!