프로젝트에서 여러 마이그레이션을 수행 한 후 몇 가지를 업데이트하기 위해 롤백하고 싶었지만 projects
테이블을 삭제하려고 갑자기이 오류가 발생했습니다. 외래 키 제약을 두 번 확인했지만 오류를 찾을 수 없습니다. 여기 SQLSTATE [23000] : 무결성 제약 조건 위반 : 1217
[Illuminate\Database\QueryException]
SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or upda
te a parent row: a foreign key constraint fails (SQL: drop table `projects`
)
[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or upda
te a parent row: a foreign key constraint fails
내 마이그레이션은 다음과 같습니다 1.create 테이블 사용자 :
public function up()
{
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->string('email', 50)->unique();
$table->string('password', 60);
$table->string('password_temp', 60);
$table->string('code', 60);
$table->boolean('active');
$table->string('remember_token', 100);
$table->timestamps();
});
}
public function down()
{
Schema::drop('users');
}
2.create 클라이언트 테이블 :
public function up()
{
Schema::create('clients', function(Blueprint $table)
{
$table->increments('id');
$table->integer('user_id')->unsigned()->index()->nullable();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
}
public function down()
{
Schema::drop('clients');
}
3.create 프로젝트 테이블 :
public function up()
{
Schema::create('projects', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->integer('status');
$table->integer('client_id')->unsigned()->index()->nullable();
$table->foreign('client_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
}
public function down()
{
Schema::drop('projects');
}
ast 마이그레이션, 내가 뭘하고있는 실수 일 수 있니?! 마이그레이션 할 때 아무런 문제가 없지만 변경 사항을 추가하기 위해 롤백 한 경우에만 나타납니다.
왜 이런 일이 발생하는지 알고 싶습니다. 언급 한 위의 단지 3 테이블이있는 경우
이것은 문제의 해답이 아닙니다. –