prisma / prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
https://www.prisma.io
Apache License 2.0
39.55k stars 1.54k forks source link

Invalid `prisma.playerProjection.create()` invocation: The provided value for the column is too long for the column's type. Column: for #14369

Closed SuspensionPoint closed 1 year ago

SuspensionPoint commented 2 years ago

Bug description

I'm getting this error when trying to create values of the following schema:

Schema:

model PlayerProjection {
  createdAt DateTime @default(now())

  week        String?
  team        String
  stats       Json
  sport       String
  season_type String
  season      String
  player_id   String  @id
  player      Json
  opponent    String?
  game_id     String
  date        String?
  company     String
  category    String
}

Error:

prisma:query BEGIN
prisma:query INSERT INTO `grades`.`PlayerProjection` (`createdAt`,`week`,`team`,`stats`,`sport`,`season_type`,`season`,`player_id`,`player`,`opponent`,`game_id`,`date`,`company`,`category`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)
prisma:query ROLLBACK
failed on player:  {
  week: null,
  team: 'NYG',
  stats: {
    rush_yd: 1071,
    rush_td: 8,
    rush_fd: 107.1,
    rush_att: 246,
    rec_yd: 434,
    rec_td: 2,
    rec_fd: 43.4,
    rec_5_9: 11.6,
    rec_40p: 5.8,
    rec_30_39: 5.8,
    rec_20_29: 11.6,
    rec_10_19: 17.4,
    rec_0_4: 11.6,
    rec: 58,
    pts_std: 206.5,
    pts_ppr: 264.5,
    pts_half_ppr: 235.5,
    gp: 18,
    fum_lost: 2,
    bonus_rec_rb: 58,
    adp_std: 22.3,
    adp_rookie: 999,
    adp_ppr: 22.3,
    adp_idp: 36.7,
    adp_half_ppr: 20.1,
    adp_dynasty_std: 31,
    adp_dynasty_ppr: 29.4,
    adp_dynasty_half_ppr: 29.3,
    adp_dynasty_2qb: 41.4,
    adp_dynasty: 999,
    adp_2qb: 36.5
  },
  sport: 'nfl',
  season_type: 'regular',
  season: '2022',
  player_id: '4866',
  player: {
    years_exp: 4,
    team: 'NYG',
    position: 'RB',
    news_updated: 1656295812160,
    metadata: { injury_override_regular_2021_6: 'Out' },
    last_name: 'Barkley',
    injury_status: null,
    injury_start_date: null,
    injury_notes: null,
    injury_body_part: null,
    first_name: 'Saquon',
    fantasy_positions: [ 'RB' ]
  },
  opponent: null,
  game_id: 'season',
  date: null,
  company: 'rotowire',
  category: 'proj'
}

PrismaClientKnownRequestError: 
Invalid `prisma.playerProjection.create()` invocation:

  The provided value for the column is too long for the column's type. Column: for
    at RequestHandler.handleRequestError (/Users/<user>/projects/Personal/draft-grader/node_modules/@prisma/client/runtime/index.js:49670:13)
    at RequestHandler.request (/Users/<user>/projects/Personal/draft-grader/node_modules/@prisma/client/runtime/index.js:49652:12)
    at async PrismaClient._request (/Users/<user>/projects/Personal/draft-grader/node_modules/@prisma/client/runtime/index.js:50572:18)
    at async Procedure.resolve [as resolver] (webpack-internal:///(api)/./src/server/router/drafts.ts:59:44)
    at async Array.<anonymous> (/Users/<user>/projects/Personal/draft-grader/node_modules/@trpc/server/dist/router-2f54c292.cjs.dev.js:101:25)
    at async callRecursive (/Users/<user>/projects/Personal/draft-grader/node_modules/@trpc/server/dist/router-2f54c292.cjs.dev.js:119:24)
    at async Procedure.call (/Users/<user>/projects/Personal/draft-grader/node_modules/@trpc/server/dist/router-2f54c292.cjs.dev.js:144:20)
    at async eval (webpack-internal:///(api)/./node_modules/@trpc/server/dist/resolveHTTPResponse-55b2c9bd.cjs.dev.js:205:24)
    at async Promise.all (index 0)
    at async Object.resolveHTTPResponse (webpack-internal:///(api)/./node_modules/@trpc/server/dist/resolveHTTPResponse-55b2c9bd.cjs.dev.js:201:24) {
  code: 'P2000',
  clientVersion: '4.0.0',
  meta: { column_name: 'for' }
}

The last section where it's suggesting that it's failing on column_name 'for' is throwing me off, because there is not column with that name in the schema.

My only guess is that the size of the stored JSON is too large, but even then I'm not sure.

How to reproduce

Using the provided environment and Prisma info, try and create a value of the provided schema.

Expected behavior

I'm expecting the create to work and add the values to the DB or at least give an error that is easily interpretable, although I'm sure it's user error.

Prisma information

Environment & setup

Prisma Version

prisma                  : 4.0.0
@prisma/client          : 4.0.0
Current platform        : darwin
Query Engine (Node-API) : libquery-engine da41d2bb3406da22087b849f0e911199ba4fbf11 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli da41d2bb3406da22087b849f0e911199ba4fbf11 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core da41d2bb3406da22087b849f0e911199ba4fbf11 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt da41d2bb3406da22087b849f0e911199ba4fbf11 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : da41d2bb3406da22087b849f0e911199ba4fbf11
Studio                  : 0.465.0
janpio commented 2 years ago

Hm, I can't reproduce this:

PS C:\Users\Jan\Documents\throwaway\14369> node .\script.js
Created new:  {
  createdAt: 2022-07-30T19:56:08.063Z,
  week: null,
  team: 'NYG',
  stats: {
    gp: 18,
    rec: 58,
    rec_fd: 43.4,
    rec_td: 2,
    rec_yd: 434,
    adp_2qb: 36.5,
    adp_idp: 36.7,
    adp_ppr: 22.3,
    adp_std: 22.3,
    pts_ppr: 264.5,
    pts_std: 206.5,
    rec_0_4: 11.6,
    rec_40p: 5.8,
    rec_5_9: 11.6,
    rush_fd: 107.1,
    rush_td: 8,
    rush_yd: 1071,
    fum_lost: 2,
    rush_att: 246,
    rec_10_19: 17.4,
    rec_20_29: 11.6,
    rec_30_39: 5.8,
    adp_rookie: 999,
    adp_dynasty: 999,
    adp_half_ppr: 20.1,
    bonus_rec_rb: 58,
    pts_half_ppr: 235.5,
    adp_dynasty_2qb: 41.4,
    adp_dynasty_ppr: 29.4,
    adp_dynasty_std: 31,
    adp_dynasty_half_ppr: 29.3
  },
  sport: 'nfl',
  season_type: 'regular',
  season: '2022',
  player_id: '4866',
  player: {
    team: 'NYG',
    metadata: { injury_override_regular_2021_6: 'Out' },
    position: 'RB',
    last_name: 'Barkley',
    years_exp: 4,
    first_name: 'Saquon',
    injury_notes: null,
    news_updated: 1656295812160,
    injury_status: null,
    injury_body_part: null,
    fantasy_positions: [ 'RB' ],
    injury_start_date: null
  },
  opponent: null,
  game_id: 'season',
  date: null,
  company: 'rotowire',
  category: 'proj'
}
All [
  {
    createdAt: 2022-07-30T19:54:52.853Z,
    week: null,
    team: 'NYG',
    stats: {
      gp: 18,
      rec: 58,
      rec_fd: 43.4,
      rec_td: 2,
      rec_yd: 434,
      adp_2qb: 36.5,
      adp_idp: 36.7,
      adp_ppr: 22.3,
      adp_std: 22.3,
      pts_ppr: 264.5,
      pts_std: 206.5,
      rec_0_4: 11.6,
      rec_40p: 5.8,
      rec_5_9: 11.6,
      rush_fd: 107.1,
      rush_td: 8,
      rush_yd: 1071,
      fum_lost: 2,
      rush_att: 246,
      rec_10_19: 17.4,
      rec_20_29: 11.6,
      rec_30_39: 5.8,
      adp_rookie: 999,
      adp_dynasty: 999,
      adp_half_ppr: 20.1,
      bonus_rec_rb: 58,
      pts_half_ppr: 235.5,
      adp_dynasty_2qb: 41.4,
      adp_dynasty_ppr: 29.4,
      adp_dynasty_std: 31,
      adp_dynasty_half_ppr: 29.3
    },
    sport: 'nfl',
    season_type: 'regular',
    season: '2022',
    player_id: '4866',
    player: {
      team: 'NYG',
      metadata: [Object],
      position: 'RB',
      last_name: 'Barkley',
      years_exp: 4,
      first_name: 'Saquon',
      injury_notes: null,
      news_updated: 1656295812160,
      injury_status: null,
      injury_body_part: null,
      fantasy_positions: [Array],
      injury_start_date: null
    },
    opponent: null,
    game_id: 'season',
    date: null,
    company: 'rotowire',
    category: 'proj'
  }
]

with this script:

const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()

async function main() {

  const newFoo = await prisma.PlayerProjection.create({
    data: {
        week: null,
        team: 'NYG',
        stats: {
          rush_yd: 1071,
          rush_td: 8,
          rush_fd: 107.1,
          rush_att: 246,
          rec_yd: 434,
          rec_td: 2,
          rec_fd: 43.4,
          rec_5_9: 11.6,
          rec_40p: 5.8,
          rec_30_39: 5.8,
          rec_20_29: 11.6,
          rec_10_19: 17.4,
          rec_0_4: 11.6,
          rec: 58,
          pts_std: 206.5,
          pts_ppr: 264.5,
          pts_half_ppr: 235.5,
          gp: 18,
          fum_lost: 2,
          bonus_rec_rb: 58,
          adp_std: 22.3,
          adp_rookie: 999,
          adp_ppr: 22.3,
          adp_idp: 36.7,
          adp_half_ppr: 20.1,
          adp_dynasty_std: 31,
          adp_dynasty_ppr: 29.4,
          adp_dynasty_half_ppr: 29.3,
          adp_dynasty_2qb: 41.4,
          adp_dynasty: 999,
          adp_2qb: 36.5
        },
        sport: 'nfl',
        season_type: 'regular',
        season: '2022',
        player_id: '4866',
        player: {
          years_exp: 4,
          team: 'NYG',
          position: 'RB',
          news_updated: 1656295812160,
          metadata: { injury_override_regular_2021_6: 'Out' },
          last_name: 'Barkley',
          injury_status: null,
          injury_start_date: null,
          injury_notes: null,
          injury_body_part: null,
          first_name: 'Saquon',
          fantasy_positions: [ 'RB' ]
        },
        opponent: null,
        game_id: 'season',
        date: null,
        company: 'rotowire',
        category: 'proj'
      },
  })
  console.log(`Created new: `, newFoo)

  const allFoo = await prisma.playerProjection.findMany()
  console.log('All', allFoo)
}

main()
  .then(async () => {
    await prisma.$disconnect()
  })
  .catch(async (e) => {
    console.error(e)
    await prisma.$disconnect()
    process.exit(1)
  })

and schema:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

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

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

model PlayerProjection {
  createdAt DateTime @default(now())

  week        String?
  team        String
  stats       Json
  sport       String
  season_type String
  season      String
  player_id   String  @id
  player      Json
  opponent    String?
  game_id     String
  date        String?
  company     String
  category    String
}

Am I doing something wrong than you?

I am using a AWS RDS MySQL running version 5.7.33-log.

(Running Prisma 4.1.1)

janpio commented 2 years ago

Ping @SuspensionPoint Can you please take a look at my reproduction? We want to take a look at this and fix it. But right now we do not know what is broken.

janpio commented 2 years ago

Can you help us out here @SuspensionPoint? With the current information we unfortunately will need to close the issue as it is not enough to understand what is going on and reproduce it. Thanks!

janpio commented 1 year ago

Closing then until someone provides more information. Please comment or open a new issue. Thanks!

mpopv commented 1 year ago

FWIW, for anyone else who landed here by googling, I got this error too and the solution was indeed that the size of the stored JSON is too large. At different points in testing I saw the column names for and = in error messages.