-
Notifications
You must be signed in to change notification settings - Fork 182
Open
Labels
Description
Steps to reproduce
- Have a LoopBack 4 microservice using a MySQL database.
- Have important data in the MySQL database belonging to the service (making
automigrate-ing bydrop-ing the database unfeasible). - Have one of the
model's fields set as a anid, by havingid: trueset in its@propertydecorator, like so:
import {Entity, model, property} from '@loopback/repository';
@model({
settings: {
mysql: {table: 'foos'},
forceId: true,
}
})
export class FooDbEntry extends Entity {
@property({
type: 'string',
id: true,
generated: false,
mysql: {
columnName: 'foo_id',
nullable: 'N'
}
})
fooId: string;
@property({
generated: false,
mysql: {
columnName: 'bar',
nullable: 'Y'
}
})
bar: string | null;
}- Have the same field not set as a primary key inside the database.
- Restart the service with
autoupdateset to be executed during startup.
Current Behavior
The field set as an id inside the model file, is not reflected as a primary key inside the database.
Actual MySQL query output
mysql> SHOW KEYS FROM foos WHERE Key_name = 'PRIMARY';
Empty set (0.00 sec)
Expected Behavior
The field set as an id inside the model file, is reflected as a primary key inside the database.
Expected MySQL query output
mysql> SHOW KEYS FROM foos WHERE Key_name = 'PRIMARY';
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| foos | 0 | PRIMARY | 1 | foo_id | A | 211 | NULL | NULL | | BTREE | | | YES | NULL |
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
1 row in set (0.01 sec)
Link to reproduction sandbox
Not applicable due to requirement to connect to MySQL database.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Icebox