Hello, I had some referential integrity problems making a model. Basically I had an article with a category and tags
For tags, create another table that has the id of the article and the tag, since it can contain more than one. Here the first problem arose because if I want to delete an article I forget the onDelete cascade in that pivot table
$table->foreign('articulo_id')->references('id')->on('articulos')->onDelete('cascade');
This made me wonder what would happen if I delete a category, how do I handle the category_id in the article, in principle I would like to put null on it and see how I handle it, since I put an OnDelete on it, it doesn't seem to me that if a category is deleted, necessarily have to delete an article. But I did not find how to do it from the migrations in Laravel or do I have to modify the value of the name when I do the destroy?
And once the migrations are edited. Is there a way to restore them without deleting the data from the database?
Assuming your foreign key is nullable , you could use
set null
:Some MySQL documentation: http://dev.mysql.com/doc/refman/5.7/en/innodb-foreign-key-constraints.html