Reputation: 111
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
Upvotes: 6
Views: 19781
Reputation: 434
Laravel eloquent ORM have auto increment, So set up primaryKey = null and increment = false.
protected $primaryKey = null;
public $incrementing = false;
Upvotes: 4
Reputation: 156
have you tried using the correct data type for post id?
$table->integer('post_id');
Upvotes: 1
Reputation: 87719
Set the primary key in your FbPostShareCount
model as
class FbPostShareCount extends Eloquent {
protected $primaryKey = 'post_id';
...
}
Upvotes: 14