简体   繁体   English

Laravel:队列作业表修改字段问题

[英]Laravel: queues jobs table modify fields problem

So basically I needed to change the id type of the jobs and failed jobs migrations created by laravel to uuid, but it shows me this error. 因此,基本上我需要将作业的id类型和laravel创建的失败的作业迁移更改为uuid,但这会向我显示此错误。

SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column \\"id\\" violates not-null constraint. SQLSTATE [23502]:不为null违反:7错误:\\“ id \\”列中的null值违反了non-null约束。

I'm using the queue database driver. 我正在使用队列数据库驱动程序。

I've tried to change the model in the framework files and works somewhat ok, but this is like my critical nuclear solution. 我试图在框架文件中更改模型,并且可以正常工作,但这就像我的关键核解决方案一样。

If there is a better and more optimal solution you can think of please go crazy. 如果有更好更好的解决方案,您可能会想到的。

Thanks in advance! 提前致谢!

The problem is caused by laravel not generating UUID automatically. 该问题是由laravel无法自动生成UUID引起的。 Normally, if you want a model to use uuid, you override its boot function and provide uuid creation logic. 通常,如果您希望模型使用uuid,则可以覆盖其引导功能并提供uuid创建逻辑。 For instance, you can see it in action here: 例如,您可以在此处查看其运行情况:

https://medium.com/binary-cabin/automatically-generating-a-uuid-on-your-laravel-models-b8b9c3599e2b https://medium.com/binary-cabin/automatically-generating-a-uuid-on-your-laravel-models-b8b9c3599e2b

However, jobs and failed-jobs tables are not models. 但是,作业和失败作业表不是模型。 If you inspect Illuminate/Queue/DatabaseQueue class, you will see that it just do basic DB updates, inserts. 如果检查Illuminate / Queue / DatabaseQueue类,您将看到它只是进行基本的数据库更新,插入。 So if you really have to change these tables to use UUID, only option you have is to refactor this core laravel code which is not suggested. 因此,如果您真的必须更改这些表以使用UUID,那么您唯一的选择就是重构该核心laravel代码(不建议使用)。

Another approach you can take is, create 2 new intermediate models (eg MyJob and MyFailedJob) for jobs and failed jobs, and with sql triggers on original table populate these table. 您可以采用的另一种方法是,为作业和失败的作业创建2个新的中间模型(例如MyJob和MyFailedJob),并在原始表上使用sql触发器填充这些表。 You can use uuid on these intermediate models. 您可以在这些中间模型上使用uuid。

Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM