eveningkid / denodb

MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno

Home Page:https://eveningkid.com/denodb-docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple Primary Key Exists

Rei-Tw opened this issue · comments

commented

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.

It's also the issue on my end,