Solucionado (ver solução)
Solucionado
(ver solução)
4
respostas

MySQL

Optei em usar MySQL e ao rodar php artisan migrate gerou a exceção abaixo:

 Illuminate\Database\QueryException  : SQLSTATE[HY000]: General error: 1005 Can't create table `series`.`temporadas` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `temporadas` add constraint `temporadas_serie_id_foreign` foreign key (`serie_id`) references `series` (`id`))
4 respostas

Aparentemente, ele não conseguiu criar a FK entre as duas tabelas. Dá uma olhada nelas, ou posta as duas aqui

public function up()
    {
        Schema::create('episodios', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('numero');
            $table->integer('temporada_id');

            $table->foreign('temporada_id')
            ->references('id')
            ->on('temporadas');

            $table->timestamps();
        });
    }
public function up()
    {
        Schema::create('temporadas', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('numero');
            $table->integer('serie_id');

            $table->foreign('serie_id')
            ->references('id')
            ->on('series');

            $table->timestamps();
        });
    }
public function up()
    {
        Schema::create('series', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('nome');
            $table->timestamps();
        });
    }
solução!

Identifiquei o problema. O id das tabelas foram gerados com BIGINT e os fk_id como INT. E id estava UNSIGNED e fk_id não.

O código precisa ficar assim:

    public function up()
    {
        Schema::create('episodios', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('numero');
            $table->unsignedBigInteger('temporada_id');

            $table->foreign('temporada_id')
            ->references('id')
            ->on('temporadas');

            $table->timestamps();
        });
    }

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software