我有几个 Laravel 迁移。
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');
});
当我使用php artisan migrate
时,我看到了这个错误
[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
问题是什么?