【发布时间】:2019-05-25 06:52:34
【问题描述】:
我正在尝试运行命令 php artisan migrate:rollback 并抛出错误无法更新或删除父行外键约束失败
现在当我运行命令 php artisan migrate 时出现问题,它成功迁移了我的所有表,但是当我运行回滚命令时,它向我抛出错误,错误是我的 purpose_of_visits 迁移
public function up()
{
Schema::create('purpose_of_visits', function (Blueprint $table) {
$table->increments('id');
$table->string('purpose', 100);
$table->string('description', 197);
$table->integer('speciality_id')->unsigned()->nullable();
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrent();
$table->softDeletes();
$table->integer('created_by')->unsigned()->nullable();
$table->integer('updated_by')->unsigned()->nullable();
$table->foreign('speciality_id')->references('id')->on('specialities')->onDelete('cascade');
$table->foreign('created_by')->references('id')->on('users')->onDelete('cascade');
$table->foreign('updated_by')->references('id')->on('users')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('purpose_of_visits');
}
和我的专业迁移:
public function up()
{
Schema::create('specialities', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 50);
$table->string('description',250)->nullable();
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrent();
$table->softDeletes();
$table->integer('created_by')->unsigned()->nullable();
$table->integer('updated_by')->unsigned()->nullable();
$table->foreign('created_by')->references('id')->on('users')->onDelete('cascade');
$table->foreign('updated_by')->references('id')->on('users')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('specialities');
}
即使我正在使用 onDelete('cascade'),我也无法弄清楚问题出在哪里 非常感谢您的帮助!
【问题讨论】:
-
你有 down() 架构吗?
-
是的,我有模式
-
您可以编辑您的帖子并包含 down() 架构
-
我编辑请重新审核
-
在回滚时,您必须先删除专业表.. 迁移只会按照创建或添加的方式发生
标签: laravel foreign-keys migration