TypeORM error when trying to do migrations

Viewed 27

I'm trying to create migrations with my application and I get the error

No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command

Strangely even in an old application that I had made and tested several times, now it also has the same problem. I've already checked the path settings and it's ok and still the error continues

package.json

{
  "dependencies": {
    "@types/body-parser": "^1.19.2",
    "@types/cors": "^2.8.12",
    "@types/dotenv": "^8.2.0",
    "@types/express": "^4.17.14",
    "@types/nodemon": "^1.19.2",
    "body-parser": "^1.20.0",
    "cors": "^2.8.5",
    "dotenv": "^16.0.2",
    "express": "^4.18.1",
    "nodemon": "^2.0.20",
    "pg": "^8.8.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "ts-node": "^10.9.1",
    "typeorm": "^0.3.9",
    "typescript": "^4.8.3"
  },
  "name": "ecomerce_api_payment",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "build": "rimraf dist & tsc",
    "dev": "nodemon --exec ts-node ./src/server.ts",
    "migration:generate": "typeorm-ts-node-commonjs -d ./src/database/config.ts migration:generate ./src/database/migrations/default",
    "migration:run": "typeorm-ts-node-commonjs -d ./src/database/config.ts migration:run"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": ""
}

database/config

import { DataSource } from "typeorm"
import dotenv from 'dotenv';

dotenv.config();

const port = process.env.DATABASE_PORT as number | undefined

export const AppDataSource = new DataSource({
    type: "postgres",
    host: process.env.DATABASE_HOST,
    port: port,
    username: process.env.DATABASE_USERNAME,
    password: process.env.DATABASE_PASSWORD,
    database: process.env.DATABASE_NAME,
    synchronize: true,
    entities: [`${__dirname}/../entities/*.{ts,js}`],
    migrations: [`${__dirname}/migrations/*.{ts,js}`],
})
0 Answers
Related