# Common Pitfalls and How to Avoid Them — Prisma / TypeORM / Sequelize

Source: https://www.skillbyai.com/en/orms/or-pitfalls

> Avoid the mistakes that bite real ORM projects: destructive sync, missing awaits, BigInt serialisation, timezones and hidden soft deletes.

## Bugs that every team meets once

Some ORM mistakes are so common they are worth memorising. **Destructive sync**: `sequelize.sync({ force: true })` drops and recreates tables, and `alter: true` or TypeORM `synchronize: true` can drop columns; keep them out of production code paths. **Missing `await`**: forgetting it means the query may run after the response is sent, errors become unhandled rejections, and you get a pending Promise instead of data. **BigInt**: databases return 64-bit integers that may not fit a JavaScript number, so Prisma maps `BigInt` columns (and some raw `COUNT` results) to the JavaScript `bigint` type, which `JSON.stringify` refuses to serialise. **Dates and timezones**: store timestamps in UTC and convert only when displaying, otherwise IST users see times shifted by five and a half hours. **Soft deletes**: Sequelize `paranoid: true` and TypeORM `@DeleteDateColumn` hide deleted rows from normal queries, which surprises anyone writing raw SQL or reports. Knowing these saves hours of debugging.

## The BigInt surprise

This plain Node.js snippet shows the error you get when an API returns a raw query result containing a `bigint`, and one way to convert it.

```js
const row = { authorId: 7, n: 12n }; // what a raw COUNT(*) can come back as
try {
  console.log(JSON.stringify(row));
} catch (e) {
  console.log(e.name + ': ' + e.message);
}
console.log(JSON.stringify(row, (k, v) => (typeof v === 'bigint' ? Number(v) : v)));
```

Output:

```
TypeError: Do not know how to serialize a BigInt
{"authorId":7,"n":12}
```

## Number() is only safe below 2^53

Converting a `bigint` with `Number()` silently loses precision above `Number.MAX_SAFE_INTEGER`. For counts that is fine; for IDs or money stored as large integers, send them to the client as strings instead.

**Quiz:** A Sequelize model uses paranoid: true. A user is 'deleted' with destroy(). What happens to the row?

- [ ] It is permanently removed from the table
- [ ] It is moved to an archive table automatically
- [ ] The whole table is truncated
- [x] It stays in the table with deletedAt set, and normal finders exclude it

*Answer:* It stays in the table with deletedAt set, and normal finders exclude it. Paranoid models perform soft deletes by setting deletedAt. Finders skip such rows unless you pass paranoid: false, and destroy({ force: true }) removes them for real.
