简体   繁体   中英

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.

SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column \\"id\\" violates not-null constraint.

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. Normally, if you want a model to use uuid, you override its boot function and provide uuid creation logic. For instance, you can see it in action here:

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. 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.

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. You can use uuid on these intermediate models.

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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