質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.39%
Next.js

Next.jsは、Reactを用いたサーバサイドレンダリングなどを行う軽量なフレームワークです。Zeit社が開発しており、nextコマンドでプロジェクトを作成することにより、開発環境整備が整った環境が即時に作成できます。

Q&A

解決済

1回答

276閲覧

npx prisma db pushでエラーがでる

gabakugik

総合スコア13

Next.js

Next.jsは、Reactを用いたサーバサイドレンダリングなどを行う軽量なフレームワークです。Zeit社が開発しており、nextコマンドでプロジェクトを作成することにより、開発環境整備が整った環境が即時に作成できます。

0グッド

0クリップ

投稿2024/06/15 12:47

編集2024/06/18 13:22

実現したいこと

npx prisma db pushでエラーがでないようにしたい。
環境 WSL2 ubuntu24.04

psql (16.3 (Ubuntu 16.3-0ubuntu0.24.04.1)) Type "help" for help. postgres=# \list List of databases Name | Owner | Encoding | Locale Provider | Collate | Ctype | ICU Locale | ICU Rules | Access privileges ------------------+----------+----------+-----------------+---------+---------+------------+-----------+----------------------- blog_nextjs_crud | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | postgres | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | template0 | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | =c/postgres + | | | | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | =c/postgres + | | | | | | | | postgres=CTc/postgres (4 rows)

schema.prisma

1// prisma/schema.prisma 2 3// This is your Prisma schema file, 4// learn more about it in the docs: https://pris.ly/d/prisma-schema 5 6// Generate the Prisma Client in JavaScript 7generator client { 8 provider = "prisma-client-js" 9} 10 11// This block of code defines the database connection. The database is a PostgreSQL database. 12// The database connection URL will be read from an environment variable named `DATABASE_URL`. 13datasource db { 14 provider = "postgresql" 15 url = env("DATABASE_URL") 16} 17 18// This block of code defines a Post model 19model Post { 20 id String @id @default(cuid()) 21 title String @db.VarChar(255) // will generate VARCHAR 22 content String // will generate TEXT 23 createdAt DateTime @default(now()) 24 updatedAt DateTime @updatedAt 25}

.envファイル

DATABASE_URL="postgresql://postgres:postgres@localhost:5432/blog_nextjs_crud?schema=public"
├── README.md ├── next-env.d.ts ├── next.config.mjs ├── node_modules ├── package-lock.json ├── package.json ├── postcss.config.mjs ├── prisma ├── public ├── src ├── tailwind.config.ts └── tsconfig.json

そのときのpostgresqlのログです。

2024-06-16 19:19:01.541 JST [269] LOG: database system is ready to accept connections 2024-06-16 19:20:36.275 JST [1714] postgres@blog_nextjs_crud FATAL: password authentication failed for user "postgres" 2024-06-16 19:20:36.275 JST [1714] postgres@blog_nextjs_crud DETAIL: User "postgres" has no password assigned. Connection matched file "/etc/postgresql/16/main/pg_hba.conf" line 125: "host all all 127.0.0.1/32 scram-sha-256" 2024-06-16 19:50:58.307 JST [7667] postgres@blog_nextjs_crud FATAL: password authentication failed for user "postgres" 2024-06-16 19:50:58.307 JST [7667] postgres@blog_nextjs_crud DETAIL: User "postgres" has no password assigned. Connection matched file "/etc/postgresql/16/main/pg_hba.conf" line 125: "host all all 127.0.0.1/32 scram-sha-256" 2024-06-16 19:51:22.893 JST [7854] postgres@blog_nextjs_crud FATAL: password authentication failed for user "postgres" 2024-06-16 19:51:22.893 JST [7854] postgres@blog_nextjs_crud DETAIL: User "postgres" has no password assigned. Connection matched file "/etc/postgresql/16/main/pg_hba.conf" line 125: "host all all 127.0.0.1/32 scram-sha-256"

発生している問題・分からないこと

prismaを使ってNext.jsでCRUDしたいんですがエラーがでます。

https://fajarwz.com/blog/simple-full-stack-crud-with-nextjs-14-postgresql-and-prisma/
をやりたい。

発生している問題・エラー
npx prisma db pushの部分でエラーがでます。
その前まではできています。

エラーメッセージ

error

1blog-nextjs-crud#npx prisma db push 2 3Error: P1000: Authentication failed against database server at `localhost`, the provided database credentials for `postgres` are not valid. 4 5Please make sure to provide valid database credentials for the database server at `localhost`.

該当のソースコード

特になし

試したこと・調べたこと

  • teratailやGoogle等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

postgresqlの知識がとぼしく解決できなかった。

補足

特になし

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

uky

2024/06/17 01:46

schema.prismaファイルを添付していただけないでしょうか?
gabakugik

2024/06/17 13:14

コメントありがとうございます。質問を修正したのでご確認よろしくお願いいたします。
uky

2024/06/18 02:22

ありがとうございます! DBを作成した際のユーザー名・パスワードは両方とも「postgres」であっていますか? postgresql://username:password@localhost:5432/ が構文としてありますのでご確認をお願いします!
gabakugik

2024/06/18 09:47

はいあっています。
uky

2024/06/19 01:52

エラーを見る限りでは、DBへのアクセスはできているが、パスワード認証に失敗しているように見えますので、可能であればユーザー名「postgres」のパスワードを再設定してから再度接続を試してみていただけますか?
gabakugik

2024/06/19 14:51

コメントありがとうございます。パスワードなしを試したところ問題が解決しました!
guest

回答1

0

自己解決

パスワードなしで解決しました。

pg_hba.conf

1# "local" is for Unix domain socket connections only 2local all all trust 3# IPv4 local connections: 4host all all 127.0.0.1/32 trust 5# IPv6 local connections: 6host all all ::1/128 trust

投稿2024/06/19 14:54

gabakugik

総合スコア13

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.39%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問