我正在阅读 an article on secure storage of credentials with postgres推荐随机 uuids
与自动递增 id
。
在原始的 postgresql 中它会是这样的:
id uuid NOT NULL DEFAULT gen_random_uuid() 主键
但是,凭借 Eloquent Eloquent ,我无法弄清楚如何实现这样的目标。 eloquent docs for 5.4提到 ->storedAs($expression)
不幸的是仅限于 MySQL。这对 postgres 来说根本不可能吗?
最佳答案
试试 ->default(DB::raw('gen_random_uuid()'));
它存在于 query builder 中文档
关于postgresql - Eloquent ORM 和 postgres 迁移 - 是否可以分配表达式默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45113590/