Hola gente de stackoverflow, estoy haciendo un proyecto de hospital y me surgió un problema que antes no sucedía. Al necesitar modificar la tabla turnos, al agregarle una nueva columna y tirar el comando php artisan migrate:refresh, me salta el error que dejo acá abajo.
PS C:\xampp\htdocs\SiHoDe> php artisan migrate
Migrating: 2019_06_04_002058_create_turnos_table
Illuminate\Database\QueryException : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'turnos' already exists (SQL: create table `turnos` (`id` int unsigned not null auto_increment primary key, `fecha_hora` timestamp not null, `paciente_id` int unsigned not null, `medico_id` int unsigned not null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
at C:\xampp\htdocs\SiHoDe\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'turnos' already exists")
C:\xampp\htdocs\SiHoDe\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:119
2 PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'turnos' already exists")
C:\xampp\htdocs\SiHoDe\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:117
Y al tirar php artisan migrate:refresh me salta este error:
Rolling back: 2019_06_03_233709_create_medicos_table
Illuminate\Database\QueryException : SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table if exists `medicos`)
at C:\xampp\htdocs\SiHoDe\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails")
C:\xampp\htdocs\SiHoDe\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:119
2 PDOException::("SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails")
C:\xampp\htdocs\SiHoDe\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:117
Please use the argument -v to see more details.
Tabla medicos:
class CreateMedicosTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('medicos', function (Blueprint $table) {
$table->increments('id');
$table->string('codigo')->unique();
$table->string('nombre_apellido');
$table->string('domicilio');
$table->unsignedInteger('localidad_id');
$table->foreign('localidad_id')->references('id')->on('localidades');
$table->string('telefono');
$table->unsignedInteger('lugar_desemp_id')->nullable();
$table->foreign('lugar_desemp_id')->references('id')->on('lugares_desemp');
$table->unsignedInteger('especialidad_id')->nullable();
$table->foreign('especialidad_id')->references('id')->on('especialidades');
$table->timestamp('fecha_nacimiento');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('medicos');
}
}
Tabla turnos:
class CreateTurnosTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('turnos', function (Blueprint $table) {
$table->increments('id');
$table->timestamp('fecha_hora');
$table->unsignedInteger('paciente_id');
$table->foreign('paciente_id')->references('id')->on('pacientes');
$table->unsignedInteger('medico_id');
$table->foreign('medico_id')->references('id')->on('medicos');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('turnos');
}
}
Ya probé eliminando las claves foraneas en las 2 tablas y sigue tirando el mismo error, ya no sé cual podría ser la solución y por eso recurro a ustedes los machos alfa lomo plateado.