I have a couple of Laravel migrations.
1-create_countries_table`
Schema::create('countries', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->timestamps();
});
2-create_cities_table
Schema::create('cities', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->smallInteger('country_id');
$table->timestamps();
$table->foreign('country_id')->references('id')->on('countries');
});
When I use php artisan migrate
, I see this error
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
(SQL: alter table `cities` add constraint cities_country_id_foreign
foreign key (`country_id`) references `countries` (`id`))
[PDOException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
What is the problem?