Commit 9ff5bd1 1 parent 3da25ae commit 9ff5bd1 Copy full SHA for 9ff5bd1
File tree 1 file changed +14
-1
lines changed
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -204,7 +204,20 @@ function mixinMigration(MySQL, mysql) {
204
204
const sql = [ ] ;
205
205
206
206
propNames . forEach ( function ( propName ) {
207
- if ( m . properties [ propName ] && self . id ( model , propName ) ) return ;
207
+ // If the field is set as an ID inside the model
208
+ if ( m . properties [ propName ] && self . id ( model , propName ) ) {
209
+ const existingIdField = actualFields ?. find (
210
+ ( { Field } ) => Field === expectedColNameForModel ( propName , m )
211
+ ) ;
212
+
213
+ // And the same field is already present inside the DB, but not set as a
214
+ // primary key
215
+ if ( existingIdField && existingIdField . Key !== 'PRI' ) {
216
+ // Set the field to а primary key
217
+ sql . push ( `ADD PRIMARY KEY (\`${ existingIdField . Field } \`)` ) ;
218
+ } else { return ; }
219
+ } ;
220
+
208
221
let found ;
209
222
const colName = expectedColNameForModel ( propName , m ) ;
210
223
if ( actualFields ) {
You can’t perform that action at this time.
0 commit comments