Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrity constraint violation on deleting Product with images #39

Closed
enricoromeo opened this issue Apr 15, 2018 · 0 comments
Closed

Integrity constraint violation on deleting Product with images #39

enricoromeo opened this issue Apr 15, 2018 · 0 comments

Comments

@enricoromeo
Copy link
Contributor

enricoromeo commented Apr 15, 2018

i have just inserted one Product into Database and, if i add some images in the product edit screen, the app goes in crash:

I got this error message

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (scotchbox.product_images, CONSTRAINT product_images_product_id_foreign FOREIGN KEY (product_id) REFERENCES products (id)) (SQL: delete from products where id = 48)

From CreateProductImagesTable i tried to modify this column
$table->foreign('product_id')->references('id')->on('products')

to
$table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');

After a "php artisan migrate:fresh", the issue should resolve.

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants