I'm trying to rollback my database, but have this error:
[Illuminate\Database\QueryException] SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table
tb_levels
)[PDOException] SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails
this is my migration code:
public function up()
{
Schema::disableForeignKeyConstraints();
Schema::create('tb_users', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id_user');
$table->string('name');
$table->string('username');
$table->string('email')->unique();
$table->integer('id_level')->unsigned();
$table->string('password', 60);
$table->rememberToken();
$table->boolean('activated')->default(false);
$table->timestamps();
$table->foreign('id_level')->references('id_level')->on('tb_levels');
});
Schema::enableForeignKeyConstraints();
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::disableForeignKeyConstraints();
Schema::table('tb_users', function(Blueprint $table){
$table->dropForeign('tb_users_id_level_foreign');
$table->dropColumn('id_level');
});
Schema::drop('tb_users');
Schema::enableForeignKeyConstraints();
}
I've tried several ways that I found in this forum, but still got that error, any help please?