Python 上的行不以任何已知的 Prisma 模式关键字开头错误

问题描述 投票:0回答:1

我正在尝试为 FastAPI 项目实现 Prisma。我添加了 Prisma 包和

schema.prisma
文件,但是当我运行
prisma validate
时它会抛出错误:

Environment variables loaded from prisma\.env
Prisma schema loaded from prisma\schema.prisma

Error: Prisma schema validation - (validate wasm)
Error code: P1012
error: Error validating: This line is invalid. It does not start with any known Prisma schema keyword.
  -->  prisma\schema.prisma:1
   | 
   | 
 1 | datasource db {
 2 |   url      = env("DATABASE_URL")
   | 
error: Error validating: This line is invalid. It does not start with any known Prisma schema keyword.
  -->  prisma\schema.prisma:2
   | 
 1 | datasource db {
 2 |   url      = env("DATABASE_URL")
 3 |   provider = "postgresql"
   | 
error: Error validating: This line is invalid. It does not start with any known Prisma schema keyword.
  -->  prisma\schema.prisma:3
   | 
 2 |   url      = env("DATABASE_URL")
 3 |   provider = "postgresql"
 4 | }
   | 
error: Error validating: This line is invalid. It does not start with any known Prisma schema keyword.
  -->  prisma\schema.prisma:4
   | 
 3 |   provider = "postgresql"
 4 | }
 5 | 
   | 

但我不明白为什么。这是我的架构:

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

generator client {
  provider             = "prisma-client-py"
  recursive_type_depth = 5
}

model User {
  id        Int     @id @default(autoincrement())
  email     String  @unique
  username  String  @db.VarChar(12)
  name      String  @db.VarChar(25)
  lastname  String  @db.VarChar(25)
  password  String  @db.VarChar(20)
}

我开始学习 prisma 所以我不知道我是否做错了什么。

python postgresql fastapi prisma
1个回答
0
投票

正如 @MatsLindh 在评论中所说,问题是由于 UTF-8 BOM 引起的,只需删除它即可解决。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.