sequelize / sequelize-auto

Automatically generate bare sequelize models from your database.
2.9k stars 527 forks source link

Sequelize Sets foreign key as primary in schema. Which in turn does not allow me to update foreign key #634

Closed Self-TT closed 1 year ago

Self-TT commented 1 year ago

Hi. I'm using sequelize-auto to generate schemas from a prebuilt database. I'm running into an issue where I need to run some update functions to update a foreign key however since sequelize-auto sets the foreign key as "primary:true" sequelize ignores it.

Below is the generated foreign key and the primary property being set to true. image

Because of the above, I cannot update the column unless I change the primary property to false like below image

Is this expected behavior for sequelize-auto to set foreign keys as primary in the schema? Is this configurable anywhere? As I don't want to update every model which has foreign keys to be primary: false.

Advice and workarounds would be appreciated.

Self-TT commented 1 year ago

Update: not a problem with sequelize auto. There was an issue with Non Identifying & Identifying relationships within my database.

sorry for the hassle hope it helps someone else in the future.