简体   繁体   中英

Prisma -> Type 'number' is not assignable to type 'never'

I'm having an issue with this strange typescript error stating that type number is not assignable to type 'never'. I would normally be able to fix, but I'm not sure what's happening with the Prisma config in my nest js project.

Here is the code in my service file. It's strange, as I'm performing the exact same logic with very similar functions, and I've never seen this error before. I've run 'prisma generate' and 'prisma migrate dev', and can confirm all the generated types and DB are up to date.

Does anyone know what I'm overlooking? Thanks!

async create(input: CreateSongToListInput): Promise<SongToList> {
    const songToList = await this.db.songToList.create({
      data:
        song_id: input.song_id,
        list_id: input.list_id,
        movie_id: input.movie_id,
        tvshow_id: input.tvshow_id,
        order: input.order,
      },
    })
    return songToList
  }

My prisma schema is as follows

model SongToList {
  id           Int    @id @default(autoincrement())
  list_id      Int
  list         List   @relation(fields: [list_id], references: [id], onDelete: Cascade)
  song_id      Int
  song         Song   @relation(fields: [song_id], references: [id], onDelete: Cascade)
  played_count Int    @default(0)
  movie_id     Int?
  movie        Movie? @relation(fields: [movie_id], references: [id], onDelete: Cascade)
  tvshow_id    Int?
  tvshow       Show?  @relation(fields: [tvshow_id], references: [id], onDelete: Cascade)
  order        Int?
  user_id      Int
  user         User   @relation(fields: [user_id], references: [id], onDelete: Cascade)
}

在此处输入图像描述

try this and tell me if works correctly

 async create(input: CreateSongToListInput): Promise < SongToList > {
    const songToList = await this.db.songToList.create({
            data: {
                songToList: {
                    create: {
                        song_id: input.song_id,
                        list_id: input.list_id,
                        movie_id: input.movie_id,
                        tvshow_id: input.tvshow_id,
                        order: input.order,

                    }
                },

            }
        }
    })
   return songToList
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM