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

Error in one-to-many example when using MySQL #1102

Closed
AppSynergy opened this issue Jan 25, 2016 · 5 comments
Closed

Error in one-to-many example when using MySQL #1102

AppSynergy opened this issue Jan 25, 2016 · 5 comments
Labels

Comments

@AppSynergy
Copy link

From the homepage:

exports.up = function(knex, Promise) {
  return knex.schema.createTable('books', function(table) {
    table.increments('id').primary();
    table.string('name');
  }).createTable('pages', function(table) {
    table.increments('id').primary();
    table.string('content');
    table.integer('book_id').references('books.id')
  });
};

I noticed:

Knex:warning - migrations failed with error: alter table `pages` add constraint pages_book_id_foreign foreign key (`book_id`) references `books` (`id`) - ER_CANT_CREATE_TABLE: Can't create table 'MY_DB_NAME.#sql-48a_de' (errno: 150)

Which, on MySQL at the least, is due to trying to add a foreign key between a signed int and an unsigned int.

Changing to:

table.integer('book_id').unsigned().references('books.id');

resolves the issue.

Cheers!

@ricardograca
Copy link
Member

This is not a bookshelf issue. Can you open a similar issue over on knex's repository?

@AppSynergy
Copy link
Author

Sure, no problem.

I saw it more as an issue with the specific example given on
http://bookshelfjs.org/, rather than an issue with knex.

On 25 January 2016 at 12:32, Ricardo Graça notifications@github.com wrote:

This is not a bookshelf issue. Can you open a similar issue over on knex's
repository?


Reply to this email directly or view it on GitHub
#1102 (comment)
.

@ricardograca
Copy link
Member

I think the example is supposed to work without having to specify an unsigned column just for one of the database adapters, that's why this is an issue with knex and not bookshelf. Or am I missing something?

@AppSynergy
Copy link
Author

I don't think it does work, not with mySQL anyhow. You need the unsigned, afaics.

Has come up a few times on knex/issues.

I can submit a PR for the tutorials if you like.

@ricardograca
Copy link
Member

Yeah, but the solution is just a workaround. I still think the migration should just work across all supported dialects, but no one has suggested that in any of those issues.

I'm not against adding a note to the docs saying that is a known issue, and a link to the issue over at knex, but it should be noted that it is a workaround for MySQL only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants