Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't reach database server at localhost:`3306 - Prisma #193

Open
ghost opened this issue Nov 8, 2022 · 2 comments
Open

Can't reach database server at localhost:`3306 - Prisma #193

ghost opened this issue Nov 8, 2022 · 2 comments
Assignees
Labels
🐞 Bug Something isn't working

Comments

@ghost
Copy link

ghost commented Nov 8, 2022

Describe the Bug (버그 설명)

When adding new user the request is failing with error message:

{
  "message": "\nInvalid `this.users.findUnique()` invocation in\n/app/src/services/users.service.ts:27:45\n\n  24 public async createUser(userData: CreateUserDto): Promise<User> {\n  25   if (isEmpty(userData)) throw new HttpException(400, \"userData is empty\");\n  26 \n→ 27   const findUser: User = await this.users.findUnique(\nCan't reach database server at `localhost`:`3306`\n\nPlease make sure your database server is running at `localhost`:`3306`."
}

Version to Reproduce (현재 사용한 버전)

v9.1.1

Steps to Reproduce (재현 순서)

  1. npx typescript-express-starter "demo"
  2. rename .env.test.local to .env (without this, the step third step is failing with Environment variable not found: DATABASE_URL)
  3. run npm run prisma:migrate
  4. Replaced mysql image with image: arm64v8/mysql (I'm using M1 Pro Mac)
  5. run docker-compose up -d
  6. add user via swagger docs
  7. see error

Expected Behavior (예상 동작)

Used should be added successfully

Actual Behavior (실제 동작)

Request if failing

@ghost ghost added the 🐞 Bug Something isn't working label Nov 8, 2022
@ghost ghost assigned ljlm0402 Nov 8, 2022
@cuongnv-dev
Copy link

Please try docker ps to ensure that your container is running

@hichemfantar
Copy link
Contributor

hichemfantar commented Jun 13, 2023

Prisma checks for .env

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

whereas the config index.ts checks for different .env file

config({ path: `.env.${process.env.NODE_ENV || 'development'}.local` });

A solution is to create a .env file and copy content of .env.development.local to .env
then update config index.ts
config({ path: ".env" });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants