This commit is contained in:
Stefan Blaginov 2025-05-02 20:01:40 +00:00 committed by GitHub
commit ace487b2ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 1 deletions

View File

@ -204,7 +204,20 @@ function mixinMigration(MySQL, mysql) {
const sql = [];
propNames.forEach(function(propName) {
if (m.properties[propName] && self.id(model, propName)) return;
// If the field is set as an ID inside the model
if (m.properties[propName] && self.id(model, propName)) {
const existingIdField = actualFields?.find(
({ Field }) => Field === expectedColNameForModel(propName, m)
);
// And the same field is already present inside the DB, but not set as a
// primary key
if (existingIdField && existingIdField.Key !== 'PRI') {
// Set the field to а primary key
sql.push(`ADD PRIMARY KEY (\`${existingIdField.Field}\`)`);
} else { return; }
};
let found;
const colName = expectedColNameForModel(propName, m);
if (actualFields) {