Pessoal, estou com um problema para criar uma foreign com as migrations do laravel.
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `users` add constraint `users_equipe_id_foreign` foreign key (`equipe_id`) references `equipe` (`id`))
at /home/vagrant/code/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: 1215 Cannot add foreign key constraint")
/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458
2 PDOStatement::execute()
/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458
Create Users seed
public function up()
{
Schema::dropIfExists('users');
Schema::enableForeignKeyConstraints();
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id')->index();
//Informações do atleta
$table->string('name');
$table->string('tel')->nullable();
$table->string('nacionalidade',2)->nullable();
$table->string('cpf', 11)->unique();
$table->date('data_nascimento')->nullable();
$table->char('genero', 1);
//Informações de login
$table->string('email')->unique();
$table->string('avatar')->nullable()->default('user_defatult.png');
$table->string('password');
$table->string('status')->nullable()->default(1);
$table->string('permission')->nullable()->default('app.atleta');
$table->timestamp('email_verified_at')->nullable();
$table->rememberToken();
//Demais informações
$table->string('cep')->nullable();
$table->string('logradouro')->nullable();
$table->string('bairro')->nullable();
$table->string('cidade')->nullable();
$table->string('uf')->nullable();
$table->string('complemento')->nullable();
$table->string('emer_nome')->nullable();
$table->string('emer_tel')->nullable();
$table->integer('equipe_id')->unsigned();
$table->timestamps();
});
}
Create Tables Equipe:
public function up()
{
Schema::dropIfExists('equipes');
Schema::create('equipes', function (Blueprint $table) {
$table->bigIncrements('id')->index();
$table->string('nome');
$table->integer('status');
$table->timestamps();
});
}
Alter Table Users
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->foreign('equipe_id')->references('id')->on('equipe');
});
}
a migration é executada nesta ordem, mas o errro persiste