Undefined column: 7 ERROR: column \"id\" does not exist

Undefined column: 7 ERROR: column \"id\" does not exist

Joe StraussJoe Strauss Posts: 4Questions: 2Answers: 0

I am following the tutorial for connecting DataTables Editor to my Postgres DB via Editor-PHP. I created the following:

`<?php include("..\DataTables.php") ?>


<?php
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Join,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;

    $editor = DataTables\Editor::inst( $db, 'shipping_log_view' )
        ->fields(
            Field::inst( 'short' ),
            Field::inst( 'po_num' ),
            Field::inst( 'packing_list' ),
            Field::inst( 'shipper' ),
            Field::inst( 'tracking_num' ),
            Field::inst( 'qty' ),
            Field::inst( 'mtc_serial' ),
            Field::inst( 'pkg_amt' ),
            Field::inst( 'mettrix_invoice' ),
            Field::inst( 'due_date' )
        )
        ->process( $_POST )
        ->json();`

The Problem I have is that when I can no longer view the table (Which was working when before I used this script. When I view the script in the browser, I get the following error:

{"error":"SQLSTATE[42703]: Undefined column: 7 ERROR: column \"id\" does not exist\nLINE 1: SELECT id as \"id\", short as \"short\" FROM shipping_log_view...\n ^","data":[]}

MY QUESTION:

Why is the script querying for a column called "id" and How do I stop it from doing that because clearly there is no column named "id"?

This question has an accepted answers - jump to answer

Answers

  • vincmeistervincmeister Posts: 136Questions: 36Answers: 4
    Answer ✓

    Hi Joe,

    trying to share,

    id is the default primary key for Editor
    if you don't have field id in your table, you must specify the primary key using ->pkey( 'yourprimarykey' )
    in my case, that helps.

    read this doc

    danny

  • allanallan Posts: 63,809Questions: 1Answers: 10,516 Site admin

    Just for information and to add to Danny's reply, you can also pass the primary key column name as an optional third parameter to the Editor::inst() constructor.

    Allan

  • Joe StraussJoe Strauss Posts: 4Questions: 2Answers: 0

    Thanks for quick responses vincmeister & allan. Defining my primary key worked like a charm :D

This discussion has been closed.