Table with No PK

Hey Forest,

Does Forest Admin have support for MySQL tables with no primary key? I’ve been trying to add one such table to our admin panel but have just been getting errors. Here is the model definition if it helps. Thank you!

// This model was generated by Forest CLI. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
  const { Sequelize } = sequelize;
  // This section contains the fields of your model, mapped to your table's columns.
  // Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
  const CredentialOcpiIdentifier = sequelize.define('credentialOcpiIdentifier', {
    countryCode: {
      type: DataTypes.STRING,
    },
    partyId: {
      type: DataTypes.STRING,
    },
    role: {
      type: DataTypes.STRING,
    },
  }, {
    tableName: 'credential_ocpi_identifier',
    underscored: true,
    timestamps: false,
  });
  CredentialOcpiIdentifier.removeAttribute('id');
  // This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
  CredentialOcpiIdentifier.associate = (models) => {
    CredentialOcpiIdentifier.belongsTo(models.ocpiCredential, {
      foreignKey: {
        name: 'credentialCredentialIdKey',
        field: 'credential_credential_id',
      },
      targetKey: 'credentialId',
      as: 'credentialCredential',
    });
  };

  return CredentialOcpiIdentifier;
};

Hey @Arda_Yurdakul,

As of today, Forest Admin does not support table without a primary key.

Updating/Removing records requires a primary key to work as expected. However, if these features aren’t a strong requirement on your end, you may be able to declare a Smart field and use it as your primary key.

Let me know if that helps.