It is impossible to figure out how to set the correct onDelete restriction for a table in Laravel. (I work with SqLite)
$table->...->onDelete('cascade'); // works $table->...->onDelete('null || set null'); // neither of them work
I have 3 migrations creating a gallery table:
Schema::create('galleries', function($table) { $table->increments('id'); $table->string('name')->unique(); $table->text('path')->unique(); $table->text('description')->nullable(); $table->timestamps(); $table->engine = 'InnoDB'; });
Creating an image table:
Schema::create('pictures', function($table) { $table->increments('id'); $table->text('path'); $table->string('title')->nullable(); $table->text('description')->nullable(); $table->integer('gallery_id')->unsigned(); $table->foreign('gallery_id') ->references('id')->on('galleries') ->onDelete('cascade'); $table->timestamps(); $table->engine = 'InnoDB'; });
Linking a gallery table with an image:
Schema::table('galleries', function($table) { // id of a picture that is used as cover for a gallery $table->integer('picture_id')->after('description') ->unsigned()->nullable(); $table->foreign('picture_id') ->references('id')->on('pictures') ->onDelete('cascade || set null || null'); // neither of them works });
I do not get any errors. In addition, even the cascade option does not work (only in the gallery table). When you delete the gallery, all pictures are deleted. But when removing the cover, do not delete the gallery (for testing purposes).
Since even a cascade does not start, I set zero is not a problem.
EDIT (workaround):
After reading this article, I changed my outline a bit. Now the image table contains the "is_cover" cell, which indicates whether this image is a cover on his album or not.
The solution to the original problem is still much appreciated!
php laravel laravel-migrations
MK Jan 01 '14 at 13:23 2014-01-01 13:23
source share