sequelize-mig icon indicating copy to clipboard operation
sequelize-mig copied to clipboard

Cannot read property 'fields' of undefined

Open irlanco opened this issue 5 years ago • 2 comments

Hi there love the package.

When a model does not have any previous indexes and I add one i get this error Cannot read property 'fields' of undefined

I receive this error when I add this in my model. I previously did not have an indexes section in the model.

indexes: [
      {
        fields: ['email'],
      }
    ]

When a different model already had the indexes section, I can add more indexes and I will create a migration correctly.

irlanco avatar Apr 21 '21 22:04 irlanco

I have this issue too, adding a new column and defining some associations caused the problem. @irlanco did you find any solutions?

alirezazarei28 avatar Jul 31 '21 12:07 alirezazarei28

Found a quick fix for this. In your file _current.json, find the model you're adding the index to, change the indexes value from the empty array to an empty object. Then run the migration command again. For example:

  1. Change "indexes": [] to "indexes": {}
  2. sequelize-mig migration:make -n foo

hgbao avatar Aug 11 '21 03:08 hgbao