I'm trying to migrate my typeorm application, and I'm getting 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, I had already created an application using typeorm with the same directory and settings as this current application, and everything worked fine and ok. But now not even my old application is doing more migrations and it's returning the same error. I wonder, how do I get the error now if I developed the entire application by creating migrations and I didn't change anything in the settings?
server.ts
import app from './app';
import { AppDataSource } from './database/config';
async function connection() {
const port = process.env.PORT;
try {
await AppDataSource.initialize();
console.log('Database connected! ');
app.listen(port);
console.log(`Listening on port ${port}`)
} catch (error) {
console.log(error);
}
}
connection();
app.ts
import express from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import dotenv from 'dotenv';
dotenv.config();
import "reflect-metadata"
const app = express();
app.use(express.json());
app.use(cors());
app.use(bodyParser());
export default app;
datasource folder
import dotenv from 'dotenv';
dotenv.config();
import { DataSource } from "typeorm"
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}`],
})
package.json
{
"name": "api-rest-typescript",
"version": "1.0.0",
"main": "server.js",
"license": "MIT",
"scripts": {
"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",
"build": "rimraf dist & tsc",
"start": "node ./dist/server.js"
},
"devDependencies": {
"@types/express": "^4.17.13",
"@types/node": "^18.0.1",
"nodemon": "^2.0.19",
"ts-node": "^10.8.2",
"typescript": "^4.7.4"
},
"dependencies": {
"@types/body-parser": "^1.19.2",
"@types/cors": "^2.8.12",
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"pg": "^8.7.3",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typeorm": "^0.3.7"
}
}