Prisma 2.21.0stable Released Apr 13, 2021
⚠️ Breaking Change Impact Score: 7/10

Prisma 2.21.0 — Release Notes & Engineering Impact

Source available — automated, not human-reviewed

Component: prisma · Channel: stable. Automated analysis, not a compatibility certification. How this works.

Analysis updated: 2026-11-01.

Breaking-change evidence from the source

  • Breaking Changes ### Aggregates are now nullable
Read the original context ↗
Source flags breaking changes — review applicability
$ npm install --save-dev --save-exact [email protected]
📄 .MD
⚡ Executive Summary (TL;DR)

Prisma 2.21.0. Source highlight: Today, we are excited to share the `2.21.0` stable release 🎉

Who Does This Impact? (Role-Based Analysis)

💻 Software Engineers & Devs

Check the source notes against the package and APIs you use before upgrading.

📊 Product & Engineering Leads

Use the documented changes to assess relevance to your product; release frequency alone is not a quality measure.

⚙️ DevOps & Security

Verify the target version, runtime requirements and rollback procedure in the official documentation.

⚠️ Breaking Changes & Deprecations (1)

  • Breaking Changes ### Aggregates are now nullable

✨ New Features & Capabilities (1)

  • feat: enable pushing a list to a scalar list

⚡ Performance & Enhancements (1)

  • Improve error message in Prisma Migrate when a provider mismatch is detected

🔧 Bug Fixes & Patches (2)

  • On PostgreSQL, when changing column types that are also in an index, Migrate would generate a `DROP COLUMN ..., ADD COLUMN ...` sequence of SQL statements. These silently drop the indexes present on the column, and migrate would only re-create them with the next migration. With this release, the issue has been fixed, and Migrate recreates the index in the same migration.
  • Fix check for orderBy aggregate
📄 View Raw Release Notes (Original Developer Log)
Today, we are excited to share the `2.21.0` stable release 🎉 🌟 **Help us spread the word about Prisma by starring the repo ☝️ or [tweeting](https://twitter.com/intent/tweet?text=Check%20out%20the%20latest%20Prisma%20release%202.21.0%20%F0%9F%9A%80%0D%0A%0D%0Ahttps://github.com/prisma/prisma/releases/tag/2.21.0) about the release.** ## Major improvements & new features ### Order by an aggregate in groupBy is now in Preview Whew, that's a tongue-twister for a neat feature. Let's say you want to group your users by the city they live in and then order the results by the cities with the most users. In `2.21.0`, now you can! ```jsx const userRatingsCount = await prisma.user.groupBy({ by: ['city'], count: { city: true, }, orderBy: { _count: { city: 'desc', }, }, }) ``` <details> <summary>Click to view the underlying model</summary> ```prisma model User { id Int @id @default(autoincrement()) email String @unique name String? city String } ``` </details> The query returns the following: ```js [ { city: 'Berlin', count: { city: 3 } }, { city: 'Paris', count: { city: 2 } }, { city: 'Amsterdam', count: { city: 1 } }, ] ``` Enable this feature with the `orderByAggregateGroup` preview flag: ```prisma generator client { provider = "prisma-client-js" previewFeatures = ["orderByAggregateGroup"] } ``` 📚 **Documentation**: [Order by aggregate group](https://www.prisma.io/docs/concepts/components/prisma-client/aggregation-grouping-summarizing#order-by-aggregate-group-preview) ## Breaking Changes ### Aggregates are now nullable Before `2.21.0`, aggregations on nullable fields always returned 0, even when there was no record or if all aggregated records were nulls. Returning 0 for null values made it impossible to differentiate between these two different results. We are changing aggregates to follow what the database returns: - All aggregated fields are now nullable. Aggregated fields can return null when there's either no record in the database or if all the aggregated records are null. - The only exception is count, which still returns 0, even if records are null or if there's no record. For example, previously, if there's no record in the database or if all records are nulls, the following aggregation: ```jsx const result = await prisma.post.aggregate({ sum: { amount: true }, }) ``` Results in: ```js { sum: { amount: 0 } } ``` The `result.sum` type is currently of type `{ amount: number }`. Starting this release, the same query returns: ```js { sum: { amount: null } } ``` And `result.sum` is of type `{ amount: number | null }` 📚 **Documentation**: [Aggregates are nullable](https://www.prisma.io/docs/concepts/components/prisma-client/aggregation-grouping-summarizing#aggregate-values-are-nullable) ### `disconnect` no longer throws an error on unconnected records Prior to `2.21.0`, if you ran the following code: ```jsx const user = await prisma.user.update({ where: { email: '[email protected]' }, data: { profile: { disconnect: true, }, }, }) ``` And **no** profile was connected to Bob, the client would throw with this error: ``` The records for relation `UserToProfile` between the `User` and `Profile` models are not connected. ``` [We learned from you](https://github.com/prisma/prisma/issues/3069) that handling this added unnecessary boilerplate to your applications. As of `2.21.0`, we've removed this error. Now, if you try disconnecting an unconnected record, the operation does nothing and passes through. **This change is unlikely to affect you** unless you explicitly handle the `disconnect` error. In that case, adjust your code because the command no longer throws an error. 📚 **Documentation**: [`$disconnect()`](https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#disconnect) ### `@default(dbgenerated(""))` is no longer permitted The `dbgenerated()` function allows you to define default values generated directly by the database and cannot yet be represented in the Prisma schema. Previously, you could pass an empty string, i.e., `@default(dbgenerated(""))`, which would fail since the contents are added into the migration SQL as `columnName COLUMN_TYPE DEFAULT <contents of dbgenerated>` As of `2.21.0`, **if a value is present, it cannot be an empty string**. If you want an empty string default, the correct syntax is `@default(dbgenerated("''")` (or other quotation marks, depending on the database provider). 📚 **Documentation**: [`dbgenerated()`](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#dbgenerated) ## Fixes and improvements ### Prisma Client - [Prisma2 packages causes Yarn install devDependencies on --prod](https://github.com/prisma/prisma/issues/1285) - [Disconnect on a null foreign key should not error ](https://github.com/prisma/prisma/issues/3069) - [`count` throws an error if `include` is specified](https://github.com/prisma/prisma/issues/3360) - [SQLite: Dates before 1970 panic. PANIC in /root/.cargo/registry/src/github.com-1ecc6299db9ec823/chrono-0.4.19/src/naive/datetime.rs:117:18invalid or out-of-range datetime](https://github.com/prisma/prisma/issues/5854) - [Conversion failed when converting from a character string to uniqueidentifier.](https://github.com/prisma/prisma/issues/5869) - [Elevated number of Timed out fetching a new connection from the pool](https://github.com/prisma/prisma/issues/5977) - [Prisma migrate CLI overrides the NODE_ENV env var and always sets it to production](https://github.com/prisma/prisma/issues/5990) - ["Error validating: The relation field ... uses the scalar fields .... At least one of those fields is required. Hence the relation field must be required as well." is too restrictive when using composite keys ](https://github.com/prisma/prisma/issues/6042) - [Count queries are very inefficient and costly](https://github.com/prisma/prisma/issues/6153) - [stack depth limit exceeded](https://github.com/prisma/prisma/issues/6274) - [Test float values over N-API bridge](https://github.com/prisma/prisma/issues/6319) - [N-API Query Engine doesn't allow more than one instance at the same time](https://github.com/prisma/prisma/issues/6356) - [[DEP0131] DeprecationWarning: The legacy HTTP parser is deprecated in Node `12.22.0`](https://github.com/prisma/prisma/issues/6460) ### Prisma Migrate - On PostgreSQL, when changing column types that are also in an index, Migrate would generate a `DROP COLUMN ..., ADD COLUMN ...` sequence of SQL statements. These silently drop the indexes present on the column, and migrate would only re-create them with the next migration. With this release, [the issue has been fixed](https://github.com/prisma/prisma/issues/6149), and Migrate recreates the index in the same migration. - [Not prettified error `This line is invalid. It does not start with any known Prisma schema keyword.` in introspection for an invalid schema.](https://github.com/prisma/prisma/issues/3435) - [Improve error message in Prisma Migrate when a provider mismatch is detected](https://github.com/prisma/prisma/issues/5181) - [SQL Server Introspection fails on Tables with Geography Data Type](https://github.com/prisma/prisma/issues/6176) - [Error when introspecting Azure SQL Server database](https://github.com/prisma/prisma/issues/6269) - [`db push` crashes when used on specific Postgres connection string with non existing database](https://github.com/prisma/prisma/issues/6277) - [Migrate leaks database password when Migration Engine binary crashes](https://github.com/prisma/prisma/issues/6426) - [Changed the phrasing of error messages for P3006. It wrongly mentioned "temporary database", it's now been corrected to mentions the shadow database.](https://github.com/prisma/prisma/issues/6436) ### Prisma Studio We worked on shipping some minor improvements and bug fixes: - [Switch theme based on OS preferences](https://github.com/prisma/studio/issues/657) - [Link to error documentation is not clickable](https://github.com/prisma/studio/issues/646) - [Error: Too many clients](https://github.com/prisma/studio/issues/643) - [Error when changing the number of related records](https://github.com/prisma/studio/issues/651) ### prisma-engines - [Make CI run tests against pgBouner again](https://github.com/prisma/prisma-engines/issues/1796) - [Fix check for orderBy aggregate](https://github.com/prisma/prisma-engines/pull/1847) - [feat: enable pushing a list to a scalar list](https://github.com/prisma/prisma-engines/pull/1805) ## Credits Huge thanks to @Sytten, @endor, @iBluemind, @schiller-manuel, @mongolyy, @matthewmueller, @paularah, @Iamshankhadeep, @meeq, @safinsingh, @darioielardi for helping! ## 📺 Join us for another "What's new in Prisma" livestream Learn about the latest release and other news from the Prisma community by joining us for another ["What's new in Prisma"](https://youtu.be/kGBBS0MvNC0) livestream. The stream takes place [on Youtube](https://youtu.be/kGBBS0MvNC0) on **Thursday, April 15** at **5pm Berlin | 8am San Francisco**.