question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting a error on one to many relationships, with percona server Mysql 5.7

See original GitHub issue

Hey 😃,

i just getting a error with this example https://eveningkid.github.io/denodb-docs/docs/guides/one-to-many with the percona server mysql 5.7

error: Uncaught Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'alter table `businesses` add constraint `businesses_ownerid_foreign` foreign key' at line 2

throw new Error(error.message);

at Connection.nextPacket (https://deno.land/x/mysql/src/connection.ts:95:17)
    at async Connection.execute (https://deno.land/x/mysql/src/connection.ts:162:19)
    at async https://deno.land/x/mysql/src/client.ts:101:14
    at async Client.useConnection (https://deno.land/x/mysql/src/client.ts:111:22)
    at async Client.execute (https://deno.land/x/mysql/src/client.ts:100:12)
    at async Function._createInDatabase (https://deno.land/x/denodb/lib/model.ts:80:5)
    at async Database.sync (https://deno.land/x/denodb/lib/database.ts:94:7)

Is mysql 5.7 not supported, or is it a bug?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
prisiscommented, Jun 17, 2020

Hey 😃, thank you for the response 😃

I switched my db to arangodb and created a client for it, its fits better for my use case.

But if i start a new project i will try denodb again 😃

1reaction
eveningkidcommented, Jun 16, 2020

Hey Daniel,

I finally managed to get MySQL 5.7 — just like yours, running on my laptop 😃

I had the exact same issue and obviously decided to fix this (we’re engineers after all). Here were the issues:

  • the MySQL driver couldn’t take multiple queries at once, I had to split them on ; (which was a similar behaviour with SQLite)
  • a foreign key was an integer, but the actual primary key it was targeting was a string. So for sure MySQL couldn’t manage to link these two!
  • dropping tables have to be the done in the right order, based on the foreign keys

So here’s the code that is now working on my side and hopefully will on yours too! 😃

import { DataTypes, Database, Model, Relationships } from "https://deno.land/x/denodb/mod.ts";

const db = new Database({ dialect: "mysql", debug: true }, {
  host: "localhost",
  username: "root",
  password: "",
  database: "mysql",
});

class Owner extends Model {
  static table = "owners";

  static fields = {
    id: {
      type: DataTypes.STRING,
      primaryKey: true,
    },
    name: DataTypes.STRING,
  };

  static businesses() {
    return this.hasMany(Business);
  }
}

class Business extends Model {
  static table = "businesses";

  static fields = {
    id: {
      type: DataTypes.STRING,
      primaryKey: true,
    },
    name: DataTypes.STRING,
    ownerId: Relationships.belongsTo(Owner),
  };

  static owner() {
    return this.hasOne(Owner);
  }
}

db.link([Owner, Business]);

await Business.drop();
await Owner.drop();

await db.sync();

await db.close();

I know this comes out of nowhere but I just wanted to let you know it’s now all fixed!

I hope you will give denodb another chance. Do not hesitate to raise any other issue, I now have MySQL to debug things out hehe

Keep in touch!

Read more comments on GitHub >

github_iconTop Results From Across the Web

MySQL Error: Too many connections - Percona
MySQL uses one thread per client connection and many active threads are performance killer. Usually, a high number of concurrent connections ...
Read more >
Percona Server Documentation
Percona Server for MySQL is an enhanced drop-in replacement for MySQL. With Percona Server for MySQL,. • Your queries will run faster and ......
Read more >
MySQL "Got an error reading communication packet" - Percona
In this blog post, we'll discuss the possible reasons for MySQL “Got an error reading communication packet” errors and how to address them....
Read more >
Update to 5.7 fails on Ubuntu 12.04.5 LTS - Percona Forum
Here's what I did: service mysql stop apt-get install percona-server-server-5.7 Install fails with the following error: dpkg: error ...
Read more >
MySQL 5.7 Reference Manual :: 5.1.7 Server System Variables
The MySQL server maintains many system variables that configure its operation. Each system variable has a default value. System variables can be set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found