Php 无法使用laravel雄辩ORM插入PostgreSQL
在发布这篇文章之前,我做了很多研究 在尝试使用Laravel eloquent ORM将记录插入PostgreSQL时,我遇到了以下错误 这就是错误:Php 无法使用laravel雄辩ORM插入PostgreSQL,php,postgresql,laravel,laravel-4,eloquent,Php,Postgresql,Laravel,Laravel 4,Eloquent,在发布这篇文章之前,我做了很多研究 在尝试使用Laravel eloquent ORM将记录插入PostgreSQL时,我遇到了以下错误 这就是错误: 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) ret
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")
这是数据库表创建架构:
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'));
});
这就是我试图执行的代码:
// 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();
我还创建了一个模型类FbPostShareCount Extendes Eloquent
我知道laravel不支持复杂的密钥,但当我使用MySQL时,这个问题并没有发生。请将
FbPostShareCount
模型中的主键设置为
class FbPostShareCount extends Eloquent {
protected $primaryKey = 'post_id';
...
}
您是否尝试过为post id使用正确的数据类型
$table->integer('post_id');
Laravel雄辩的ORM具有自动递增功能,因此设置primaryKey=null和increment=false
protected $primaryKey = null;
public $incrementing = false;
同样的错误。为了记录,我在数据库中使用了组合键,我附加了架构。据我所知,eloquent目前不支持组合键。@MoFetch是正确的。但是,正如前面所说的,它应该是整数作为PK的ID。等待反馈。问题解决了吗?