NPM TypeORM is throwing the error message "Duplicate migrations" when changes are made to a migration file

Recently, I made a modification to an existing table by adding a new column using the command

npm run migration:generate <filename>
.

Unfortunately, I realized later on that I had misspelled the column name and needed to correct it (showComission -> showCommission).

Since this was only in my local environment, I went ahead and updated the column name in the migration file and executed the command npm run migration:run.

However, I encountered a duplicated migration error, which led me to check the log where I found the message concerning the modified export class name as **addShowCommissionToCorporationProfile1643792138368.

The following steps were taken:

- typeorm migration:run

- query: SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'abc' AND TABLE_NAME = 'migrations'

- query: SELECT * FROM abc.migrations migrations ORDER BY id DESC

Further along, I encountered an error during migration run:
Error: Duplicate migrations: addShowCommissionToCorporationProfile1643792138368

at 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! <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d2b3b0b1ffb3a2bb92e3fce2fce2">[email protected]</a> 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.

In an attempt to fix the issue, I tried reverting using npm run migration:revert, but faced the same error. I then reverted the migration file back to its original state and created a new migration file specifically for renaming the column using

npm run migration:generate --filename
, yet still encountered the same error. In one final effort to resolve the issue, I deleted the newly created migration file and ran only the original migration file (initial state), however, the error persisted.

I am seeking advice on how to rectify this situation as all I wanted to do was simply rename the column...

If more information or clarification is needed, please feel free to ask.

Your help and guidance are greatly appreciated.

Answer №1

Encountered a similar issue while working on a NestJS project. The workaround that worked for me was to remove the dist folder, then rebuild the project, allowing me to successfully execute the new migration.

After some recent changes to the project's structure, including relocating the migrations to a different directory, I discovered an odd behavior in Nest. Moving files triggered a partial rebuilding of the project in the destination folder but not in the original location, leading to duplicate migrations. A full rebuild resolved the issue by eliminating the duplicates in the build.

Answer №2

I encountered a similar problem and was taken aback by the lack of search results on Google regarding this issue.

I am currently utilizing it for a NestJS application, however, deleting the dist folder and rebuilding (as mentioned in other solutions) did not resolve the issue.

The root cause turned out to be using an index file in the migrations directory that exported the migrations along with the migration files themselves. This caused TypeORM to import the migrations twice - once from the migration file and once from the index file.

In such scenarios, there are 2 possible solutions:

  • Remove index.ts from the migrations folder
  • Modify the value of the migrations option in your DataSource configuration to specify the exact path to the index file like path/to/migrations/index.{ts,js} instead of using a regex with wildcards in the filename. Additionally, ensure that new migrations are also added to the index file.

Answer №3

By running npm run build, I was able to fix the issue at hand.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Revolutionary custom binding with Bootstrap popover integration

Utilizing asp.net mvc with dynamic knockout columns, I am facing an issue with one of the column headers named "Status". The desired functionality includes a bootstrap popover that displays information when a user clicks a font-icon question mark. Here is ...

Modifying the nodeJS executable path on Windows without administrator privileges

My Windows PC does not grant me admin rights, but the admin has already installed Node at C:\Program Files\nodejs, with version 12: PS C:\Users\JO52900> node -v v12.18.3 PS C:\Users\JO52900> Get-Command node CommandType ...

NPM-AUDIT has detected two critical vulnerabilities. What steps should I take next?

npm audit was run on my project and flagged the following vulnerability: High severity issue of Command Injection in a dependency of @angular-devkit/build-angular [dev] Vulnerable Path: @angular-devkit/build-angular > @ngtools/webpack > tree-kill ...

How can I retrieve Feature Information exclusively from the currently visible WMS layers in OpenLayers 3?

I am working with an Openlayers map that features multiple WMS layers. I am trying to use the "getGetFeatureInfoUrl" function to request feature information, but only for the layers that are currently visible on the map. Additionally, if there are multiple ...

Is it possible to execute PHP without using Ajax when clicking on a Font Awesome icon?

So, besides using Ajax, is there another solution to achieve the same result? Can a font-awesome icon be turned into a button without Ajax? In case you're unfamiliar with what I mean by a font-awesome icon, here's an example: <i id="like1" on ...

What methods can be used to modify the behavior of tiptap when pasting plain text?

Currently, my goal is to create a visual editor by utilizing the tiptap library. Although v2 of tiptap is more commonly used, there are instances where v1 is necessary. However, I encountered an issue with tiptap's behavior when pasting plain text, ...

Tips on eliminating redundant rows while retaining a single one in an Access database

https://i.sstatic.net/k95kj.png Looking for a generic query to remove duplicate rows in my Access database. I have encountered this issue with multiple tables. Can anyone help? ...

Unresponsive JavaScript on specific element IDs

I'm experimenting with making three lines perform different animations: line 1 rotating 45deg and translating, line 2 becoming opaque, and line 3 rotating -45deg and translating. Check out my JS Fiddle here <a href="#"><div id="menu" onclic ...

Configure WebStorm so that node_modules is set as the library root, while simultaneously excluding it from indexing

Can WebStorm projects be configured to set the node_modules as the library root, while also excluding it from indexing? I thought I saw a project that had node_modules marked as both library root and excluded, but I'm unsure how to do this. Does anyo ...

Does JSON have a special reserved key for identifying the time?

I've noticed an interesting issue when logging the json string of a key labeled tid - it always shows up as 0. Take a look at this example: var transaction = {tid:1, type:0, time:126312736}; var transStr = JSON.stringify(transaction); console.log(tra ...

What are the steps to create a class diagram for a NodeJS application?

For my final year project, I am looking to develop an application using Node API. As we delve into drawing the class diagram, it occurs to me that unlike Java or C#, Node JS does not have a built-in class concept. What would be the most effective approac ...

Obtaining essential data while facing a redirect situation

I need to extract the og data from a specific URL: https://www.reddit.com/r/DunderMifflin/comments/6x62mz/just_michael_pouring_sugar_into_a_diet_coke/ Currently, I am using open-graph-scraper for this task. However, the issue I'm facing is that it i ...

Storing values in an array when checkboxes are selected within an ng-repeat loop in AngularJS

I am facing a situation where I need to populate an array with values when a checkbox is checked within an ng-repeat iteration. <li ng-repeat="player in team.players"> <div class="row"> <div class="col-md-3 m-t-xs"> <inp ...

Troubleshooting issue with Bootstrap slider: CSS display problem

After downloading the Bootstrap slider from this link: https://github.com/seiyria/bootstrap-slider, I navigated to \bootstrap-slider-master\dist and transferred the bootstrap-slider.js and bootstrap-slider.min.js files to my js folder. Additional ...

Ways to position divs without causing them to collapse or override existing divs

I am currently developing a demonstration in which users can select jQuery areas to create square blocks. When a user selects an area and adds a comment with color, the entire block is displayed at a specific position. This feature is working perfectly as ...

What is a clever way to monitor the completion of a forEach loop using promises?

I'm new to promises and I'm attempting to use them for the first time. After the completion of the forEach loop, I want to call another function for additional processing. However, when using forEach, the function insertIDBEvents is only printed ...

Is it possible to implement a Promise.some() function that includes a timeout

Scenario - collect multiple URLs and cache the responses. URLs that are processed quickly (e.g. within 500ms) are included in the current pass, while those that take longer are still cached for use in the next round (approximately 10 minutes later in our a ...

A tool that showcases outcomes determined by the interaction of two variables

I have two select inputs: <select id="inputA"> <option>1</option> <option>2</option> <option>3</option> </select> <select id="inputB"> <option>1</option> <option>2</opti ...

Fixing a node-gyp error using npm audit fix: A step-by-step guide

Currently encountering an issue while trying to run npm audit fix. I am looking to upgrade my node.js version from v0.10.32 to v10. Operating Environment OS: CentOS release 6.10 (Final) Node.js: v0.10.32 Package Details Name Current Wanted ...

Errors have been observed when using JavaScript variables that begin with the symbol $

For the longest time, I've used JavaScript variable names that begin with $ to signify that they hold jQuery values. For example: $buttons = $( 'button' ); However, a couple of nights ago, I encountered an issue when loading the page in the ...