-1
I am working my first relationship of one to one tables in Laravel for countries and locations, created the models and migrate them to the two tables.
Country table:
public function up()
{
Schema::create('countries', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
$table->timestamps();
});
}
And the table of locations:
public function up()
{
Schema::create('locations', function (Blueprint $table) {
$table->id();
$table->integer('country_id')->unsigned();
$table->integer('latitude');
$table->integer('longitude');
$table->timestamps();
$table->foreign('country_id')
->references('id')
->on('countries')
->onDelete('cascade');
});
}
I executed the command php artisan migrate
to import tables into the database:
What is returned is the erro 1215
, I opened phpMyAdmin and went to the database designer and checked that the relationship was not really created:
I went back to the migrate up() function and set the field size to 20 characters to see if this was the problem and ran the command php artisan migrate
and the error persisted.
Exactly, the guys in the columns didn’t match.
– bfavaretto