File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 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) {
204204 const sql = [ ] ;
205205
206206 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+
208221 let found ;
209222 const colName = expectedColNameForModel ( propName , m ) ;
210223 if ( actualFields ) {
You can’t perform that action at this time.
0 commit comments