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