diff --git a/lib/mysql.js b/lib/mysql.js index b7253c9..c34c026 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -403,11 +403,13 @@ MySQL.prototype.alterTable = function (model, actualFields, actualIndexes, done, propNames.forEach(function (propName) { if (propName === 'id') return; var found; - actualFields.forEach(function (f) { - if (f.Field === propName) { - found = f; - } - }); + if (actualFields) { + actualFields.forEach(function (f) { + if (f.Field === propName) { + found = f; + } + }); + } if (found) { actualize(propName, found); @@ -417,13 +419,15 @@ MySQL.prototype.alterTable = function (model, actualFields, actualIndexes, done, }); // drop columns - actualFields.forEach(function (f) { - var notFound = !~propNames.indexOf(f.Field); - if (f.Field === 'id') return; - if (notFound || !m.properties[f.Field]) { - sql.push('DROP COLUMN `' + f.Field + '`'); - } - }); + if (actualFields) { + actualFields.forEach(function (f) { + var notFound = !~propNames.indexOf(f.Field); + if (f.Field === 'id') return; + if (notFound || !m.properties[f.Field]) { + sql.push('DROP COLUMN `' + f.Field + '`'); + } + }); + } // remove indexes aiNames.forEach(function (indexName) {