admin管理员组文章数量:1023868
Is there a way to disable the automatic generated primary key inside Sequelize JS?
We create our tables inside PostgreSQL using Sequelize's sync method. But we've a problem with our junction tables.... We don't want a primary key in our junction table, but Sequelize generates one automatically if we don't specify one our selves. I can specify a primary key on all columns, but that's not the best way to do it....
Anyone who knows how to disable primary keys inside Sequelize JS?
Is there a way to disable the automatic generated primary key inside Sequelize JS?
We create our tables inside PostgreSQL using Sequelize's sync method. But we've a problem with our junction tables.... We don't want a primary key in our junction table, but Sequelize generates one automatically if we don't specify one our selves. I can specify a primary key on all columns, but that's not the best way to do it....
Anyone who knows how to disable primary keys inside Sequelize JS?
Share Improve this question asked Oct 17, 2014 at 8:39 Erik van de VenErik van de Ven 5,0056 gold badges45 silver badges85 bronze badges 3- where you able to find a solution for this? – user1130272 Commented Apr 28, 2015 at 11:04
-
1
Well we don't use the sync method anymore. We create new tables and edit them by using the migrations of Sequelize. So after every deployment we directly deploy new changes for our DB. And in our models we use posite primary keys for the junction tables. So just add
primaryKey: true
to multiple columns, whose bination makes them unique. So theusers
table has an columnid
as primary key,books
has an columnid
as primary key. Butuser_books
(= junction table) has 2 primary keys:user_id
andbook_id
Not how we want it, but works best. – Erik van de Ven Commented Apr 29, 2015 at 12:41 - Thanks so much, i was struggling with the same since yesterday and did not find a solution, Thanks again i will go your way – user1130272 Commented Apr 29, 2015 at 13:31
1 Answer
Reset to default 5Model.removeAttribute("id");
More documentation removeAttribute
Is there a way to disable the automatic generated primary key inside Sequelize JS?
We create our tables inside PostgreSQL using Sequelize's sync method. But we've a problem with our junction tables.... We don't want a primary key in our junction table, but Sequelize generates one automatically if we don't specify one our selves. I can specify a primary key on all columns, but that's not the best way to do it....
Anyone who knows how to disable primary keys inside Sequelize JS?
Is there a way to disable the automatic generated primary key inside Sequelize JS?
We create our tables inside PostgreSQL using Sequelize's sync method. But we've a problem with our junction tables.... We don't want a primary key in our junction table, but Sequelize generates one automatically if we don't specify one our selves. I can specify a primary key on all columns, but that's not the best way to do it....
Anyone who knows how to disable primary keys inside Sequelize JS?
Share Improve this question asked Oct 17, 2014 at 8:39 Erik van de VenErik van de Ven 5,0056 gold badges45 silver badges85 bronze badges 3- where you able to find a solution for this? – user1130272 Commented Apr 28, 2015 at 11:04
-
1
Well we don't use the sync method anymore. We create new tables and edit them by using the migrations of Sequelize. So after every deployment we directly deploy new changes for our DB. And in our models we use posite primary keys for the junction tables. So just add
primaryKey: true
to multiple columns, whose bination makes them unique. So theusers
table has an columnid
as primary key,books
has an columnid
as primary key. Butuser_books
(= junction table) has 2 primary keys:user_id
andbook_id
Not how we want it, but works best. – Erik van de Ven Commented Apr 29, 2015 at 12:41 - Thanks so much, i was struggling with the same since yesterday and did not find a solution, Thanks again i will go your way – user1130272 Commented Apr 29, 2015 at 13:31
1 Answer
Reset to default 5Model.removeAttribute("id");
More documentation removeAttribute
本文标签: javascriptDisable Primary Key in Sequelize JSStack Overflow
版权声明:本文标题:javascript - Disable Primary Key in Sequelize JS - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745562993a2156275.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论