実現したいこと
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の知識がとぼしく解決できなかった。
補足
特になし
schema.prismaファイルを添付していただけないでしょうか?
コメントありがとうございます。質問を修正したのでご確認よろしくお願いいたします。
ありがとうございます!
DBを作成した際のユーザー名・パスワードは両方とも「postgres」であっていますか?
postgresql://username:password@localhost:5432/
が構文としてありますのでご確認をお願いします!
はいあっています。
エラーを見る限りでは、DBへのアクセスはできているが、パスワード認証に失敗しているように見えますので、可能であればユーザー名「postgres」のパスワードを再設定してから再度接続を試してみていただけますか?
コメントありがとうございます。パスワードなしを試したところ問題が解決しました!
回答1件
あなたの回答
tips
プレビュー