簡體   English   中英

當我想使用 Prisma.schema 中添加的 model 時出現“屬性不存在”

[英]"Property does not exist" when I want to use model added in Prisma.schema

我正在使用 NextJS Framework 和 Prisma 進行 ReactJS 項目,以管理與數據庫的連接和查詢。

在我的本地項目中,找到了支持model,當我在我的 API 中使用它並構建我的項目時,一切正常。

但是當我在生產服務器 (Plesk) 上推送我的項目時,構建顯示這個 typescript 錯誤,因為它沒有找到支持model:

./src/pages/api/support/index.ts:27:26
Type error: Property 'support' does not exist on type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>'.

路徑./src/pages/api/support/index.ts是我想使用支持的地方 model

我的prisma.schema

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

generator client {
  provider = "prisma-client-js"
}

model User {
  id              Int       @id @unique @default(autoincrement())
  gender          String?
  firstName       String
  lastName        String
  email           String    @unique
  phone           String
  birthday        DateTime?
  income          Float?
  pincode         Int?
  points          Float?
  token           String    @db.Text
  ipAddress       String
  kyc             Kyc[]
  createdAt       DateTime  @default(now())
  updatedAt       DateTime?
  isValidated     Boolean   @default(false)
  roleId          Int
  role            Role      @relation(fields: [roleId], references: [id])
  Alerts          Alerts[]
  Support Support[]
}

model Kyc {
  id        Int       @id @unique @default(autoincrement())
  name      String
  validated Boolean   @default(false)
  path      String
  createdAt DateTime  @default(now())
  updatedAt DateTime? @updatedAt
  user      User      @relation(fields: [userId], references: [id])
  userId    Int
}

model Alerts {
  id         Int      @id @unique @default(autoincrement())
  type       TYPE     @default(NOBLOCKED)
  message    String   @db.Text
  transferId Int      @unique
  fromUserId Int
  read       Boolean  @default(false)
  createdAt  DateTime @default(now())
  user       User     @relation(fields: [fromUserId], references: [id])
}

model Role {
  id   Int    @id @unique @default(autoincrement())
  name String
  User User[]
}

model Support {
  id        Int     @id @unique @default(autoincrement())
  subject   String
  message   String  @db.Text
  createdAt DateTime  @default(now())
  userId          Int
  user            User      @relation(fields: [userId], references: [id])
}

enum TYPE {
  BLOCKED
  NOBLOCKED
}

不知道每次push最新的改動需要用prisma migrate dev還是prisma migrate deploy

我嘗試了prisma generateprisma migrate dev但仍然有同樣的錯誤。 我不得不重新啟動 VSCode,現在一切正常

我重新啟動了我的 Visual Studio 代碼,它開始正常工作。

我忘了等待

const user = prisma.user.findUnique({ 
  where: {
    userId: authorUserId
  },
  select: {
    id: true
  }
})

但應該是:

const user = **await** prisma.user.findUnique({ 
  where: {
    userId: authorUserId
  },
  select: {
    id: true
  }
})

筆記! 我只是指問題的標題,而不是內容。 當您不使用正確的節點版本時,也可能會引發此錯誤,例如將 nvm 與舊節點版本一起使用的情況。

使用prisma generate命令,但模式仍被標記為紅色。 我必須重新啟動我的 web 風暴 IDE 才能修復它。

在 VSCode 中重啟 typescript 服務器CTRL + SHIFT + P然后輸入: restart TS Server

就我而言,我創建了一個名為Post的模式,但我調用了await prisma.posts 它應該被稱為await prisma.posts 確保你不做Typo 😅

“DetailedHTMLProps”類型上不存在屬性<buttonhtmlattributes< div><div id="text_translate"><p> 我正在創建一個可重復使用的“按鈕”,我想添加一個href以在單擊時將其帶到另一個頁面。</p><p> 錯誤:</p><blockquote><p> 類型 '{ children: ReactNode; href:字符串; onMouseOver: (event: any) =&gt; void; onMouseOut: (事件: 任何) =&gt; void; 樣式:CSS屬性; }' 不能分配給類型 'DetailedHTMLProps&lt;ButtonHTMLAttributes, HTMLButtonElement&gt;'。</p><p> 類型“DetailedHTMLProps&lt;ButtonHTMLAttributes, HTMLButtonElement&gt;”上不存在屬性“href”。 您指的是 'ref' 嗎?</p></blockquote><h5> 哦,代碼:</h5><pre> import React from 'react'; type ButtonProps = { style: React.CSSProperties; children: React.ReactNode; href: string; }; function MouseOver(event: any) { event.target.style.opacity = '90%' } function MouseOut(event: any) { event.target.style.opacity = '' } function Button({ style, children, href }: ButtonProps) { return ( &lt;button href={href} onMouseOver={MouseOver} onMouseOut={MouseOut} style={style} &gt; {children} &lt;/button&gt; ) } export default Button;</pre><h5> 我已經嘗試過使用這種可能性:</h5><pre> import Link from 'next/link' function Button({ style, children, href }: ButtonProps) { return ( &lt;Link href={href}&gt; &lt;button onMouseOver={MouseOver} onMouseOut={MouseOut} style={style} &gt; {children} &lt;/button&gt; &lt;/Link&gt; ) }</pre><p> 這樣它就可以工作,但是代碼要求我重用的所有按鈕都必須放置一個href ,我只希望 1 個按鈕具有將我帶到注冊頁面的href 。 </p></div></buttonhtmlattributes<>

[英]Property does not exist on type 'DetailedHTMLProps<ButtonHTMLAttributes

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 為什么我的 schema.prisma 在自動保存時沒有自動添加“@relation”? Prisma model 代 - 類型“Readonly&lt;{}&gt;”上不存在屬性“posts” 類型 Pick 上不存在屬性“_id” Typescript:類型“{}”.ts 上不存在屬性“set” “DetailedHTMLProps”類型上不存在屬性<buttonhtmlattributes< div><div id="text_translate"><p> 我正在創建一個可重復使用的“按鈕”,我想添加一個href以在單擊時將其帶到另一個頁面。</p><p> 錯誤:</p><blockquote><p> 類型 '{ children: ReactNode; href:字符串; onMouseOver: (event: any) =&gt; void; onMouseOut: (事件: 任何) =&gt; void; 樣式:CSS屬性; }' 不能分配給類型 'DetailedHTMLProps&lt;ButtonHTMLAttributes, HTMLButtonElement&gt;'。</p><p> 類型“DetailedHTMLProps&lt;ButtonHTMLAttributes, HTMLButtonElement&gt;”上不存在屬性“href”。 您指的是 'ref' 嗎?</p></blockquote><h5> 哦,代碼:</h5><pre> import React from 'react'; type ButtonProps = { style: React.CSSProperties; children: React.ReactNode; href: string; }; function MouseOver(event: any) { event.target.style.opacity = '90%' } function MouseOut(event: any) { event.target.style.opacity = '' } function Button({ style, children, href }: ButtonProps) { return ( &lt;button href={href} onMouseOver={MouseOver} onMouseOut={MouseOut} style={style} &gt; {children} &lt;/button&gt; ) } export default Button;</pre><h5> 我已經嘗試過使用這種可能性:</h5><pre> import Link from 'next/link' function Button({ style, children, href }: ButtonProps) { return ( &lt;Link href={href}&gt; &lt;button onMouseOver={MouseOver} onMouseOut={MouseOut} style={style} &gt; {children} &lt;/button&gt; &lt;/Link&gt; ) }</pre><p> 這樣它就可以工作,但是代碼要求我重用的所有按鈕都必須放置一個href ,我只希望 1 個按鈕具有將我帶到注冊頁面的href 。 </p></div></buttonhtmlattributes<> 類型“從不”上不存在屬性“roleName” 類型“{}”上不存在屬性“dehydratedState” Prisma PostgreSQL queryRaw 錯誤代碼 42P01 表不存在 類型 &#39;{ props: ReactNode; 上不存在屬性 &#39;className&#39; }&#39;
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM