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
merged 2 commits into from Aug 24, 2018
Merged

Conversation

@ostriandoni
Copy link
Contributor

@ostriandoni ostriandoni commented Aug 24, 2018

Introduction

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

AND

$ 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

Motivation

To make the tutorial code running as expected.

Proposed solution

  • to fix ER_CANNOT_ADD_FOREIGN: Cannot add foreign key constraint:-
    Refer to this knex/knex#245 (comment)
  • to fix ER_ROW_IS_REFERENCED: Cannot delete or update a parent row: a foreign key constraint fails:-
    Reorder table drop

Current PR Issues

None

Alternatives considered

None

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

@ricardograca ricardograca commented Aug 24, 2018

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
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
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
Labels
Projects
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants