Skip to content

Can't customize Primary Key type or name #1762

@ferminminetto

Description

@ferminminetto

Informations

  • Node.js: 10.0.8
  • npm: 6.2.0
  • Strapi: 3.0.0-alpha.13.1
  • Database: MySQL
  • Operating system: Ubuntu 18.04

What is the current behavior?
I'm using Strapi to connect with an existing table in a MySQL table. Sadly, the id column of such table it's not called id, it's called work_id. To solve this I used in my model's JSON settings file the following configuration:

{
  "connection": "default",
  "collectionName": "works",
  "primaryKey": "work_id",
  "info": {
    "name": "Works",
    "description": "",
    "mainField": "work_id"
  },
  "attributes": {
    "work_id": {
      "type": "integer",
      "required": true
    },
   ...

It lists the objects from the database well, but when I try to enter the details of an object it throws an error saying: Error: Undefined binding(s) detected when compiling SELECT query: select `works`.* from `works` where `works`.`work_id` = ? limit ?`

Steps to reproduce the problem
Connect to an existing table of a database using a different PK name.

What is the expected behavior?
I should be able to enter the detail view of the object from that type of content.

Suggested solutions
I'm not sure!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions