adithya.hebbar
Wed Aug 28 2024
To rename a table in TypeORM
, follow these steps:
• Create a new migration.
npx typeorm migration:create -n RenameTable
This will create a new migration file in the migrations
directory
• Edit the Migration File:
import { MigrationInterface, QueryRunner } from "typeorm";
export class RenameTable1724826351040 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.renameTable('old_table_name', 'new_table_name');
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.renameTable('new_table_name', 'old_table_name');
}
}
• Run the migration:
npm run typeorm -- migration:run
#typeorm #js