Hi Wappler Community,
I am trying to figure out how to create a composite primary key in the wappler database. Can someone point me to the right resource or let me know how I can accomplish this?
Thanks in advance!
Hi Wappler Community,
I am trying to figure out how to create a composite primary key in the wappler database. Can someone point me to the right resource or let me know how I can accomplish this?
Thanks in advance!
You can’t do it directly from the UI.
You would need to create a migration file, undo the changes, edit it and reapply the migration.
Not wappler specific per say, but since using knex behind the scenes somewhat relevant
Not able to find much useful/working info online about composite keys in knex
I just get errors when using .primary. Only get it working with .unique
table.integer("item_id").unsigned();
table.integer("parent_item_id").unsigned();
table.unique(["item_id", "parent_item_id"]);
If there are any examples of using two foreign keys as a composite primary much appreciated
What errors do you get?
Just redid this in a hurry … have tried many variations
It seems like the placement of the .primary is wrong somehow ?
return knex.schema.createTable("public.bom_item", function (table) {
table.integer("parent_item_id").unsigned();
table.integer("child_item_id").unsigned();
table.primary(["parent_item_id", "child_item_id"]);
table.foreign("child_item_id").references("id").inTable("item");
table.foreign("parent_item_id").references("id").inTable("item");
I need to be more patient when reading the docs
Added a constraint and now it works.
Awesome @JonL
I’ve changed this to a feature request as it would save some time to be able to add it from the UI directly. I’m constanly undoing changes to be able to edit the migration file for this, using the right increments in Postgres and adding timestamps columns.
Good idea
I write all my migration files in VS code due to speed (copy/paste) and small missing features
What’s your workflow on vsc for knex for wappler?
How do you handle the naming convention and wappler_migrations table?
Long time since I started a new project so not sure if I remember correctly.
I think I made the first migration in wappler, renamed it to 01_xxx.is and try to control the migration sequence manually. Then mimic that file.
So just I just write/create them in vsc and migrate/rollback from wappler. wappler_migrations table rolls along with that unless I make a stupid move, which has happened a few times
More or less like I do.
The database manager needs a little bit of love from the team when 4.x is released for advanced uses
I Noticed that when I create a seed file in wappler on a table with a composite primary not all columns are included in the seed.
Can anyone confirm ?