A NestJS application demonstrating TypeORM with PostgreSQL integration.
- Copy environment variables:
cp env.example .env- Start services:
# Production
docker-compose up --build
# Development
docker-compose -f docker-compose.dev.yml up --build- Access:
- App: http://localhost:3000
- PostgreSQL: localhost:5432
- Install dependencies:
yarn install- Setup PostgreSQL:
createdb typeorm_bug- Copy environment and run migrations:
cp env.example .env
npm run migration:run
npm run seed- Start development server:
yarn start:devyarn start- Start production serveryarn start:dev- Start development server with hot reloadyarn test- Run unit testsyarn test:e2e- Run e2e tests
This project demonstrates a TypeORM bug that occurs when creating and deleting entities with many-to-many relationships.
Important: These errors occur only in TypeORM version 0.3.26. In version 0.3.25, all operations work correctly without any constraint violations.
Request:
POST /feeds/resources
Content-Type: application/json
{
"title": "React Documentation",
"type": "documentation",
"url": "https://react.dev",
"categoryIds": ["550e8400-e29b-41d4-a716-446655440003"]
}Error Response:
{
"statusCode": 400,
"message": "null value in column \"resource_id\" of relation \"feed_resources_categories\" violates not-null constraint"
}SQL Statement:
INSERT INTO "feed_resources_categories"("id", "created_at", "updated_at", "resource_id", "category_id", "order") VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT) RETURNING "id", "created_at", "updated_at"Request:
DELETE http://localhost:3000/feeds/resources/6ba7b810-9dad-11d1-80b4-00c04fd430c8Error Response:
{
"statusCode": 400,
"message": "null value in column \"resource_id\" of relation \"feed_resources_categories\" violates not-null constraint"
}This indicates a problem with TypeORM's handling of many-to-many relationships where the foreign key constraints are not being properly managed during entity operations.
# Access PostgreSQL shell
docker-compose exec postgres psql -U postgres -d typeorm_bug
# Run migrations manually
docker-compose exec app npm run migration:run
# Run seeders manually
docker-compose exec app npm run seedMIT