Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoupdate error: index or statistics already exists on table #180

Closed
Narrator opened this issue Feb 24, 2018 · 5 comments
Closed

Autoupdate error: index or statistics already exists on table #180

Narrator opened this issue Feb 24, 2018 · 5 comments
Labels

Comments

@Narrator
Copy link

I get the following message whenever I run autoupdate:

"error":{"message":"The operation failed because an index or statistics with name 'principalId_NONCLUSTERED_ASC_idx' already exists on table 'dbo.RoleMapping'.","stack":"RequestError: The operation failed because an index or statistics with name 'principalId_NONCLUSTERED_ASC_idx' already exists on table 'dbo.RoleMapping'
The table name doesn't matter, cause the error is thrown on different tables every time. The first run is fine, but whenever I kill the app and restart it, this error is thrown.

Here's the code I'm using in boot/auto-update.js

'use strict';

module.exports = function(app, done) {
  var logger = require('../../server/logger');
  var log = logger.child({module: 'auto-update'});

  var mssql = app.dataSources.mssql;

  mssql.autoupdate(function(err) {
    if (err) {
      log.error({error: err}, 'Error autoupdating DB');
      return done(err);
    }
    log.info('Database updation complete.');
    done();
  });
};
@Narrator Narrator changed the title Autoupdate error Autoupdate error: index or statistics already exists on table Feb 24, 2018
@stale
Copy link

stale bot commented Apr 25, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 25, 2018
@stale
Copy link

stale bot commented May 9, 2018

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@stale stale bot closed this as completed May 9, 2018
@javiersuazomatus
Copy link

javiersuazomatus commented Feb 13, 2019

I have the same problem. @Narrator Could you solve it?

my model definition:

{
  "name": "OIDCModel",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "name": {
      "type": "string",
      "required": true
    },
    "key": {
      "type": "string",
      "required": true
    },
    "value": {
      "type": "string",
      "required": true,
      "mssql": {
        "dataType": "text"
      }
    },
    "grantId": {
      "type": "string"
    },
    "expiresAt": {
      "type": "date",
      "required": true
    },
    "consumed": {
      "type": "boolean",
      "default": false
    }
  },
  "indexes": {
    "name_key": {
      "columns": "name,key"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

@pumppi
Copy link

pumppi commented Jan 5, 2020

I have the same issue? How you solved?

@ataft
Copy link
Contributor

ataft commented Apr 7, 2020

This is due to a bug in migration.js where it uses async.each instead of async.eachSeries. async.each has no order, so the index create was happening before the drop. I've created this PR to fix the issue:
#228

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants