javascriptpostgresqlapollo-serverprismaprisma-graphql

prisma create with nested connect throws error


I'm running into a problem, where connecting a model to multiple items in another model, in a create call seems to throw the following error:

The error:

Invalid `prisma.movie.create()` invocation:
Error occurred during query execution:
ConnectorError(ConnectorError {
user_facing_error: None, kind: QueryError(Error {
 kind: Db, cause: Some(DbError {
    severity: "ERROR", parsed_severity: None, code: SqlState("42601"),
    message: "syntax error at or near \"ON\"", detail: None, hint: None,
    position: Some(Original(93)), where_: None, schema: None, table: None,
    column: None, datatype: None, constraint: None, 
    file: Some("scan.l"), line: Some(1006), routine: Some("scanner_yyerror") 
    })
 }) 
})

The code responsible for the transaction:

const genresData = genres.map((genre) => ({ name: genre.name }));
await prisma.movie.create({
            data: {
                title: details.title,
                description: details.overview,
                // ...
                genres: {
                    connect: genresData,
                },
            },
            select: {
                tmdbId: true,
                title:true,
                // ...
            },
        });

assuming that the Genre model has a unique field, name.

the bizarre part is that everything seems to be working fine on my local machine but not on the server hosting my app.


Solution

  • I seem to have fixed the problem.

    In my case, there was a difference between the version of PostgreSQL I was running on my local machine and my server.

    My server was running postgresql-9.2 while I was using postgresql-13 locally, so upgrading my server's Postgres version fixed the issue.