I don't think the error can be related to array casting. That error comes from the DB and, like it says, it's an integrity constraint violation. That means there's a missing foreign key or a unique key violation somewhere.
Integrity constraint violation with encrypted array
Hello,
I need to cast the datasource_credentials field as an encrypted:array.
When I use the factory, I get this error.
$company = Company::factory()->create([
'datasource' => 'pipedrive',
'datasource_credentials' => [
'some_key' => 'sdlkjfghdiklfjgf',
'some_other_key' => 'sdlkjfghdiklfjgf',
]];
Integrity constraint violation: 4025
First I thought it was due to the factory, but no.
The problem is exactly the same when I try to encrypt an array from a standard form via the UI.
Hmmm ... how can I solve this ?
Thanks for your help.
V
@vincent15000 I'm a bit confused since there are no FK or Unique constraints on the column, yet you get a constraint violation. Maybe there's some JSON-related CHECK constraint on the column, since you defined it as JSON in the migration? I don't think Laravel adds one automatically, but you should still check it. Call this in the database and tell me what you see:
SELECT * from INFORMATION_SCHEMA.CHECK_CONSTRAINTS;
If there's some JSON rule, then that's the issue. By the way, the column type shouldn't be JSON since you're storing an encrypted string there, not JSON.
That still wouldn't explain why the first insert works with encryption. But let's see the output first.
Please or to participate in this conversation.