【发布时间】:2015-07-15 11:07:39
【问题描述】:
我有几个 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
有什么问题?
【问题讨论】:
-
不应该
refrences('id')是references('id')?
标签: mysql laravel pdo artisan-migrate