schema.prismaがないのでなんとも言えないですね。
前も回答したときにコメントしたかと思いますが、回答側が想像しながらコメントしなければならない質問はあまり良いものではないです。
- そもそもschema.prismaは存在していますか?
- URL先のことをやりたい…とのことですが、どこまでやって、何ができてなくて、何を達成したいのかわからないです。明確に書いてもらえますか?
prismaを使えるようにしたいをしたい。
環境 WSL2 ubuntu24.04
psql -U postgres
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
// prisma/schema.prisma
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Generate the Prisma Client in JavaScript
generator client {
provider = "prisma-client-js"
}
// This block of code defines the database connection. The database is a PostgreSQL database.
// The database connection URL will be read from an environment variable named `DATABASE_URL`.
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// This block of code defines a Post model
model Post {
id String @id @default(cuid())
title String @db.VarChar(255) // will generate VARCHAR
content String // will generate TEXT
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
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
prismaを使ってNext.jsでCRUDしたいんですがエラーがでます。
https://fajarwz.com/blog/simple-full-stack-crud-with-nextjs-14-postgresql-and-prisma/
をやりたい。
npx prisma db pushの部分でエラーがでます。
その前まではできています。
blog-nextjs-crud#npx prisma db push
Error: P1000: Authentication failed against database server at `localhost`, the provided database credentials for `postgres` are not valid.
Please make sure to provide valid database credentials for the database server at `localhost`.
ここに問題・エラーに対して試したことを記載してください。
ググってみたけどわからなかった。
よろしくお願いします。
schema.prismaがないのでなんとも言えないですね。
前も回答したときにコメントしたかと思いますが、回答側が想像しながらコメントしなければならない質問はあまり良いものではないです。
@gabakugik
Questioner質問内容を修正しました。よろしくお願いします。
PostgreSQLのログは確認しましたか?
blog_nextjs_crudのAccess privilegesに問題がないか確認してみてはいかがでしょうか。
@gabakugik
Questioner2024-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"
ログです。なんかパスワードが間違っているみたいなんですけど....
どう直したらいいかわからないです
エラーはデータベースに接続する際にパスワードが一致していないことを示しています。
データベースへの接続方法を指定する DATABASE_URL
の postgres:postgres
の部分は、 ユーザー名:パスワード
を表しますが、 postgres
ユーザーにはパスワードが不要のようです。 postgres:postgres
を postgres
に書き換えてみるとどうですか?
@gabakugik
Questionerやってみましたけどだめでした。
Error: P1000: Authentication failed against database server at localhost
, the provided database credentials for postgres
are not valid.
Please make sure to provide valid database credentials for the database server at localhost
.
のエラーが出ます。
パスワードなしでログインする方法を選びました。
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust