无法使用laravel eloquent ORM插入PostgreSQL

 卿为倾峰888 发布于 2023-01-18 14:39

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

尝试使用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时没有出现这个问题

1 个回答
  • FbPostShareCount模型中的主键设置为

    class FbPostShareCount extends Eloquent {
    
        protected $primaryKey = 'post_id';
    
        ...
    }
    

    2023-01-18 14:42 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有