【发布时间】:2019-10-05 15:59:36
【问题描述】:
我有一个带有外键的简单 laravel 迁移。
public function up()
{
Schema::create('smp_posts', function (Blueprint $table) {
$table->increments('id');
$table->integer('project_id')->unsigned();
// Some other stuff
$table->foreign('project_id')->references('id')->on('smp_projects')->onDelete('cascade');
});
}
当我运行迁移命令php artisan migrate:refresh。我收到此错误:
照亮\数据库\查询异常:
SQLSTATE[2BP01]:依赖对象仍然存在:7
错误:无法删除表 smp_projects,因为其他对象依赖于它 详细信息:表 smp_posts 上的约束 smp_posts_project_id_foreign 取决于表 smp_projects
通常应该删除所有孩子,因为我将onDelete() 设置为级联。正确的?怎么了?
【问题讨论】:
-
可能 smp_projects 迁移的日期在 sms_posts 之后,请检查迁移的名称。
-
在 smp_projects 之后没有 smp_posts
标签: php sql laravel postgresql laravel-migrations