Can I use a different column name for the primary key?

Can I use a different column name for the primary key?

emozioemozio Posts: 5Questions: 3Answers: 0

I noticed that when I changed the name of my PK column "ID" to "sID", it produced the following error:

"DataTables warning: table id=example - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'field list'"

May I conclude that this tells me that I shouldn't be using a different name for the 'id' column?
If so, is there a way to change this setting so that I can use a column with a different name? In addition, this column is not an INT, but a VARCHAR.

I would really appreciate your help.

Thank you.

This question has an accepted answers - jump to answer

Answers

  • gehornegehorne Posts: 10Questions: 2Answers: 1
    Answer ✓

    I don't think anything is keeping you from changing it to sID, you just have to modify your code to ask for the correct fields. The error your getting is from your DB saying, you ask for the field 'id' but I don't have a field 'id'

    If your using editor, go into your php and modify your code to reflect the change, Here is a sample.

    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'people', 'id' )
    ->fields(
    Field::inst( 'person' )
    ->validator( 'Validate::notEmpty' )
    )
    ->process( $_POST )
    ->json();

    In this example, I think you can just change it to read

    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'people', 'sID' )
    ->fields(
    Field::inst( 'person' )
    ->validator( 'Validate::notEmpty' )
    )
    ->process( $_POST )
    ->json();

    Hope this helps.

    GEH

  • emozioemozio Posts: 5Questions: 3Answers: 0

    @gehorne

    Thank you for your solution, this will definitely help.

  • c_bindingc_binding Posts: 3Questions: 0Answers: 0

    is there documentation for the PHP APIs?

  • allanallan Posts: 64,032Questions: 1Answers: 10,555 Site admin
This discussion has been closed.