Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix many-to-many tutorial code #1888

merged 2 commits into from
Aug 24, 2018


Copy link


When I try to implement code from this tutorial, I keep getting this error message:

$ knex migrate:latest

Knex:warning - migration file "20180824170607_initial_tables.js" failed
Knex:warning - migration failed with error: alter table `authors_books` add constraint `authors_books_author_id_foreign` foreign key (`author_id`) references `authors` (`id`) - ER_CANNOT_ADD_FOREIGN: Cannot add foreign key constraint


$ knex migrate:rollback

Knex:warning - migration file "20180824170607_initial_tables.js" failed
Knex:warning - migration failed with error: drop table `books` - ER_ROW_IS_REFERENCED: Cannot delete or update a parent row: a foreign key constraint fails


To make the tutorial code running as expected.

Proposed solution

Current PR Issues


Alternatives considered


@ricardograca ricardograca added this to To Do in Version 0.14.0 via automation Aug 24, 2018
Copy link

There is still a chance that this migration will fail with clients other than SQLite or when using a connection pool with more than 1 connection, but it's still an improvement, so many thanks.

@ricardograca ricardograca merged commit fc89cb6 into bookshelf:master Aug 24, 2018
Version 0.14.0 automation moved this from To Do to Done Aug 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
No open projects

Successfully merging this pull request may close these issues.

None yet

2 participants