自定义主键Laravel + Apiato
问题描述:
我创建了具有自定义主键的表。它是uuid“message_id”。自定义主键Laravel + Apiato
但是,试图将数据插入到它的时候,我收到以下消息_
“在‘字段列表’...未知列‘ID’”。
试图与
protected $primaryKey = 'message_id';
public $incrementing = false;
,但没有运气。
我的模型看起来像:
protected $table = 'messages';
protected $primaryKey = 'message_id';
public $incrementing = false;
protected $fillable = [
'message_id',
'sender_id',
'recipient_id',
'message_text',
'time',
];
查询:
$newMessage = $this->messageRepository->create([
'sender_id' => $sender_id,
'recipient_id' => $recipient_id,
'message_text' => $message_text,
]);
$newMessage->save();
答
我发现什么问题。在模型中我有Use Uuids;
特质的UUID已经预定义的“'default_uuid_column' => 'id'
”
节目表的说明。 REAL表格描述。 – Amarnasan
Schema :: create('messages',function(Blueprint $ table){ $ table-> uuid('message_id'); $ table-> uuid('sender_id'); $ table-> uuid('recipient_id '); $表 - >串(' MESSAGE_TEXT '); $表 - >布尔型(' 看到 '); $表 - >初级(' MESSAGE_ID'); $表 - >时间戳(); $ table-> softDeletes(); }); –
不,打开一个mysql shell,运行'DESCRIBE yourtable;'并发布输出。你的代码看起来不错;我有一种感觉,你的桌子与迁移不同步。 –