Knex.Schema: How to create composite unique key?
See original GitHub issueFor example,
ALTER TABLE users ADD UNIQUE KEY(LoginID, Email);
ALTER TABLE users ADD UNIQUE KEY(Email);
ALTER TABLE users ADD UNIQUE KEY(LoginID);
How do I do it with Knex.Schema.createTable
Issue Analytics
- State:
- Created 10 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
How do I add a Composite primary key with Knex.js?
If you need to create a composite primary key, call it on a table with an array of column names instead. Constraint name...
Read more >Schema Builder | Knex.js
If you need to create a composite index, pass an array of column to columns . Deferrable unique constraint are supported on Postgres...
Read more >How to create Composite Primary Key? - Wappler Community
You would need to create a migration file, undo the changes, edit it and reapply the migration.
Read more >Composite keys | Objection.js - GitHub Pages
Composite (compound) keys are fully supported. Just give an array of columns where you would normally give a single column name. Composite primary...
Read more >Knex(postres) - Is there a way to have a column unique only ...
That would be a unique constraint defined on both columns: ALTER TABLE tab ADD UNIQUE (orgid, name);. That will exclude only rows where...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe you should be able to do this with:
Let me know if it doesn’t seem to be working.
Works, thanks! Preparing to switch from Sequelize.