6

I did my research a lot before posting this.

I am getting the following error when trying to insert a record into PostgreSQL using Laravel eloquent ORM.

This is the error:

Illuminate \ Database \ QueryException

SQLSTATE[42703]: Undefined column: 
7 ERROR: column "id" does not exist LINE 1: ...ed_at", "created_at") 
values ($1, $2, $3, $4) 
returning "id" ^ (SQL: insert into "fb_post_like_counts" ("post_id", "count", "updated_at", "created_at") values (293843523498_10152007721598499, 0, 2014-03-12 16:56:24, 2014-03-12 16:56:24) returning "id")

This is the database table create schema:

Schema::create('fb_post_shares_counts', function($table)
{
    //
    $table->string('post_id');
    $table->string('count')->default(0);

    //  created_at updated_at deleted_at
    $table->timestamps();
    $table->softDeletes();

    // set composite keys   
    $table->primary(array('post_id', 'updated_at'));
});

and this is the code i am trying to execute:

// SAVE POST SHARES
$post_share_count   =   new FbPostShareCount;
$post_share_count->post_id   =  $response['id'];
$post_share_count->count    =   $fql_post['share_count'];       
$post_share_count->save();

and I created a model class FbPostShareCount extends Eloquent.

I know that laravel does not support complex keys but this problem did not occur when I was using MySQL

1
  • 1
    Awaiting feedback. Is it solved? Commented Jun 2, 2015 at 11:34

3 Answers 3

14

Set the primary key in your FbPostShareCount model as

class FbPostShareCount extends Eloquent {

    protected $primaryKey = 'post_id';

    ...
}
Sign up to request clarification or add additional context in comments.

3 Comments

same error. Just for the record I am using composite keys in the database I attached the schema.
as far as I'm aware eloquent does not currently support composite keys.
@MoFetch The Antonio Carlos Ribeiro is right. But, as arcsum also has said, it should be INTEGER as ID for PK.
4

Laravel eloquent ORM have auto increment, So set up primaryKey = null and increment = false.

protected $primaryKey = null;

public $incrementing = false;

Comments

1

have you tried using the correct data type for post id?

$table->integer('post_id');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.