I have an error when relating by foreign key, it generates the table but not the relationship. I already deleted the tables and generated them again and nothing I use php artisan migrate
https://gyazo.com/7d8d84a46ba23775ca49a3a91833995d
public function up()
{
Schema::create('students', function (Blueprint $table) {
$table->increments('id');
$table->string('rude');
$table->integer('peoples_id')->unsigned();
$table->foreign('peoples_id')
->references('id')->on('peoples')
->onDelete('cascade');
$table->timestamps();
});
}
public function up()
{
Schema::create('peoples', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 150);
$table->string('firstname', 75);
$table->string('lastname', 75);
$table->timestamps();
});
}
The problem I see is that apparently you are creating the students table first before the peoples table, which you are trying to reference and that is why it does not find it. Unless the error is something else (in case you use a very old version of MySQL for example), the order of the migrations that you show should be something like this:
I ran into a similar problem and the solution was to create the tables and then the relationships.
Whenever I create tables with migrations I first do the Schema::create and then a Schema::table with the relationships.
Leaving the migration similar to this: