Open pedrohllima opened 3 years ago
$table->integer('serie_id')->unsigned(); <==== Essa seria a solução?
$table->foreign('serie_id') ->references('id') ->on('series');
Sim também está correto, aqui geralmente aplicamos o tipo unsignedInteger direto
$table->unsignedInteger('temporada_id')
mas no fim o resultado é o mesmo :)
Para fazer a alteração do campo:
PS C:\Users\Trader\Documents\controle-series> php artisan migrate Migrating: 2021_04_15_184833_alterar_atributo_temporada
Illuminate\Database\QueryException
SQLSTATE[23000]: Integrity constraint violation: 19 FOREIGN KEY constraint failed (SQL: DROP TABLE temporadas)
at C:\Users\Trader\Documents\controle-series\vendor\laravel\framework\src\Illuminate\Database\Connection.php:678 674▕ // If an exception occurs when attempting to run a query, we'll format the error 675▕ // message to include the bindings with SQL, which will make this exception a 676▕ // lot more helpful to the developer instead of just the database's errors. 677▕ catch (Exception $e) { ➜ 678▕ throw new QueryException( 679▕ $query, $this->prepareBindings($bindings), $e 680▕ ); 681▕ } 682▕
1 C:\Users\Trader\Documents\controle-series\vendor\laravel\framework\src\Illuminate\Database\Connection.php:471 PDOException::("SQLSTATE[23000]: Integrity constraint violation: 19 FOREIGN KEY constraint failed")
2 C:\Users\Trader\Documents\controle-series\vendor\laravel\framework\src\Illuminate\Database\Connection.php:471 PDOStatement::execute()
https://github.com/jairlima-dev/controle-series/blob/986cbfb7faa09b3370629be8ad8f161b505d0a11/database/migrations/2021_04_10_144717_create_temporadas_table.php#L19-L23
Neste exemplo acima pode gerar um erro ao criar o indice da chave estrageira, pois a primary key da tabela series foi declarada como unsignedInteger mas na tabela temporadas o series_id ta como integer