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

Multiple Primary Key Exists #377

Open
Rei-Tw opened this issue Feb 6, 2023 · 1 comment
Open

Multiple Primary Key Exists #377

Rei-Tw opened this issue Feb 6, 2023 · 1 comment

Comments

@Rei-Tw
Copy link

Rei-Tw commented Feb 6, 2023

Hi,

I'm facing a little issue while attempting to sync db.

this is my code, it works when creating the tables, but when they already exists it fails:

class User extends Model {
  static table = "user";
  static timestamps = true;

  static fields = {
    username: {
      type: DataTypes.STRING,
      primaryKey: true,
    },
    firstname: { type: DataTypes.STRING, allowNull: false },
    lastname: { type: DataTypes.STRING, allowNull: false },
    password: { type: DataTypes.STRING, allowNull: false },
    salt: { type: DataTypes.STRING, allowNull: false },
  };
}

class Firewall extends Model {
  static table = "firewall";
  static timestamps = true;

  static fields = {
    name: { primaryKey: true, type: DataTypes.STRING },
    apiUrl: { type: DataTypes.STRING, allowNull: false },
    token: { type: DataTypes.STRING, allowNull: false },
  };
}

const db = new Database(connector, true);

db.link([Firewall, User]);
db.sync();

const models = {
  user: User,
  firewall: Firewall,
};

export { db, models };

And i'm having that error:

error: Uncaught Error: Multiple primary key defined
      throw new Error(error.message);
            ^
    at PoolConnection.nextPacket (https://deno.land/x/mysql@v2.11.0/src/connection.ts:216:13)
    at async PoolConnection.execute (https://deno.land/x/mysql@v2.11.0/src/connection.ts:271:21)
    at async https://deno.land/x/mysql@v2.11.0/src/client.ts:97:14
    at async Client.useConnection (https://deno.land/x/mysql@v2.11.0/src/client.ts:107:14)
    at async Client.execute (https://deno.land/x/mysql@v2.11.0/src/client.ts:96:12)
    at async MySQLConnector.query (https://deno.land/x/denodb@v1.2.0/lib/connectors/mysql-connector.ts:80:22)
    at async Database.query (https://deno.land/x/denodb@v1.2.0/lib/database.ts:240:21)
    at async Function.createTable (https://deno.land/x/denodb@v1.2.0/lib/model.ts:172:5)
    at async Database.sync (https://deno.land/x/denodb@v1.2.0/lib/database.ts:210:7)

I can't understand why as I don't seem to have "multiple primary keys defined", only 1 per table.

@pagebook1
Copy link

It's also the issue on my end,

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

No branches or pull requests

2 participants