Olá.
Criei o arquivo de migration AdicionaCampoAssistido com o comando
php artisan make:migration adiciona_campo_assistido --table=episodios
e alterei o aquivo para adicionar o campo 'assistido' na tabela 'episodios'
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AdicionaCampoAssistido extends Migration
{
public function up()
{
Schema::table('episodios', function (Blueprint $table) {
$table
->boolean('assistido')
->deafault(false);
});
}
public function down()
{
Schema::table('episodios', function (Blueprint $table) {
$table->dropColumn('assistido');
});
}
}
Mas quando vou executar a migration com o comando php artisan migrate acontece o seguinte erro:
C:\Users\Usuario\Desktop\Alura\controle-series>php artisan migrate
Migrating: 2019_11_29_154138_adiciona_campo_assistido
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1 Cannot add a NOT NULL column with default value NULL (SQL: alter table "episodios" add column "assistido" tinyint(1) not null)
at C:\Users\Usuario\Desktop\Alura\controle-series\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 PDOException::("SQLSTATE[HY000]: General error: 1 Cannot add a NOT NULL column with default value NULL")
C:\Users\Usuario\Desktop\Alura\controle-series\vendor\laravel\framework\src\Illuminate\Database\Connection.php:452
2 PDO::prepare("alter table "episodios" add column "assistido" tinyint(1) not null")
C:\Users\Usuario\Desktop\Alura\controle-series\vendor\laravel\framework\src\Illuminate\Database\Connection.php:452
Please use the argument -v to see more details.