Laravel-auditing: Pivot table without id column

Created on 12 Sep 2019  路  1Comment  路  Source: owen-it/laravel-auditing

| Q | A
| ----------------- | ---
| Bug? | yes
| New Feature? | no
| Framework | Laravel
| Framework version | 6.x.y
| Package version | 9.x.y
| PHP version | 7.3.y

Actual Behaviour

When updating a pivot table without an id column it throws an error that the auditable_id cannot be null

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'auditable_id' cannot be null

Expected Behaviour

Insert without auditable_id for pivot tables

Steps to Reproduce

calling $model->relationship()->updateExistingPivot($relationship_id, $data) in a controller throws the error SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'auditable_id' cannot be null

Possible Solutions

Update migration to nullableMorphs('auditable') however this results in null values being recorded for old_values. Needs to record old_values through relationship instead of by pivot id

Most helpful comment

Update migration to nullableMorphs('auditable') however this results in null values being recorded for old_values.

Instead, you can add auto-incrementing primary key and public $incrementing = true; on pivot

>All comments

Update migration to nullableMorphs('auditable') however this results in null values being recorded for old_values.

Instead, you can add auto-incrementing primary key and public $incrementing = true; on pivot

Was this page helpful?
0 / 5 - 0 ratings