微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 无法使用laravel eloquent ORM插入PostgreSQL

在发布之前我做了很多研究.

尝试使用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) 
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扩展了Eloquent.

我知道laravel不支持复杂的密钥,但是当我使用MysqL时没有出现这个问题

解决方法:

将FbPostShareCount模型中的主键设置为

class FbPostShareCount extends Eloquent {

    protected $primaryKey = 'post_id';

    ...
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐