I previously add a column to an existing table using, npm run migration:generate <filename>
.
However, I later realized that I misspelled the column name so I wanted to rename the column. (showComission -> showCommission)
Since it was just in a local environment, I modified the column name on the migration file and run npm run migration:run
.
The duplicated migration error occurred and here's the log.
**addShowCommissionToCorporationProfile1643792138368 is the modified export class name.
typeorm migration:run
query: SELECT * FROM
INFORMATION_SCHEMA
.COLUMNS
WHERETABLE_SCHEMA
= 'abc' ANDTABLE_NAME
= 'migrations'query: SELECT * FROM
abc
.migrations
migrations
ORDER BYid
DESCError during migration run:
Error: Duplicate migrations: addShowCommissionToCorporationProfile1643792138368at MigrationExecutor.checkForDuplicateMigrations at MigrationExecutor.getMigrations at MigrationExecutor.<anonymous> at step at Object.next at fulfilled at processTicksAndRejections npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] migration:run: `typeorm migration:run`
npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] migration:run script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
After that I try to revert npm run migration:revert
, but the exact same error occurred. So instead, I changed the migration file back to its initial state and use npm run migration:generate --filename
to create migration file for renaming the column but the same error stills occurred.
Lastly, I deleted newly created migration file and run only the original migration file (initial state) and run migration again, but the same error stills occurred.
Can anyone advise me how could I fixed this mess?
I just wanted to rename the column...
Please let me know if you need any additional info or more clarification about the situation.
Appreciate all your helps.
I previously add a column to an existing table using, npm run migration:generate <filename>
.
However, I later realized that I misspelled the column name so I wanted to rename the column. (showComission -> showCommission)
Since it was just in a local environment, I modified the column name on the migration file and run npm run migration:run
.
The duplicated migration error occurred and here's the log.
**addShowCommissionToCorporationProfile1643792138368 is the modified export class name.
typeorm migration:run
query: SELECT * FROM
INFORMATION_SCHEMA
.COLUMNS
WHERETABLE_SCHEMA
= 'abc' ANDTABLE_NAME
= 'migrations'query: SELECT * FROM
abc
.migrations
migrations
ORDER BYid
DESCError during migration run:
Error: Duplicate migrations: addShowCommissionToCorporationProfile1643792138368at MigrationExecutor.checkForDuplicateMigrations at MigrationExecutor.getMigrations at MigrationExecutor.<anonymous> at step at Object.next at fulfilled at processTicksAndRejections npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] migration:run: `typeorm migration:run`
npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] migration:run script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
After that I try to revert npm run migration:revert
, but the exact same error occurred. So instead, I changed the migration file back to its initial state and use npm run migration:generate --filename
to create migration file for renaming the column but the same error stills occurred.
Lastly, I deleted newly created migration file and run only the original migration file (initial state) and run migration again, but the same error stills occurred.
Can anyone advise me how could I fixed this mess?
I just wanted to rename the column...
Please let me know if you need any additional info or more clarification about the situation.
Appreciate all your helps.
Share Improve this question asked Feb 7, 2022 at 6:14 hans1125hans1125 4279 silver badges16 bronze badges 2- have you find any solution?, I am facing same issue. – Hamza T Commented May 4, 2022 at 4:54
- in my case the name of the class inside multiple migrations was same... changed that to unique values and it worked as it should – Akber Iqbal Commented Jun 4, 2024 at 4:33
4 Answers
Reset to default 15I got the same error on a NestJS project. The solution for me was to delete the dist folder, and rebuild the project, afterwards I could run the new migration.
Explanation: We just changed the project structure recently, and moved the migrations to a different folder. However, Nest has a weird "bug": when we move files, it rebuilds the part of the project where we moved the file, but not necessarily the part of the project from where we removed it. Hence the duplicate migrations in this case. When we rebuild the whole thing, there are no longer duplicate migrations in the build.
I ran into a similar issue and was surprised by lack of Google results on this issue.
I am also using it for a NestJS application, but deleting dist
folder and running a build again (as suggested in other answers) didn't help.
Turned out the reason was that I used an index file in the migrations folder which exported the migrations in addition to the migration files themselves. So when TypeORM scans the project for migrations (in case you provide a regex for migration files) it imports it twice - from the migration itself and from the index file.
So for a case like this you have 2 options:
- Delete
index.ts
from the migrations folder - Change the value of the
migrations
option of your DataSource to usepath/to/migrations/index.{ts,js}
instead of a regex with*
in the filename. In that case you also need to make sure that new migrations are added to the index file.
I exec npm run build and the problem solved.
When using TypeScript migration files and typeorm-ts-node-commonjs
to run them, .js
files will be generated. This causes a data source path such as **/migrations/*.{js,ts}
to fail with the duplicate migrations error as the glob hits both .js
and .ts
files.
The remedy is to remove .js
files from the path specification. E.g., **/migrations/*.ts
.