这是我的迁移代码:
public function up()
{
Schema::create('foos', function(Blueprint $table) {
// Primary key
$table->increments('id');
// Standard
$table->engine = 'InnoDB';
$table->timestamps();
$table->softDeletes();
});
Schema::create('bars', function(Blueprint $table) {
// Primary key
$table->increments('id');
// Define foreign key
$table->integer('foo_id')->unsigned;
// Foreign key contraints
// NOTE: causes "General error: 1215 Cannot add foreign key constraint"
// $table->foreign('foo_id')->references('id')->on('foos');
// Standard
$table->engine = 'InnoDB';
$table->timestamps();
$table->softDeletes();
});
}
public function down()
{
Schema::drop('foos');
Schema::drop('bars');
}
当定义外键约束的代码没有被注释掉时,我在命令行上得到如下错误:General error: 1215 Cannot add foreign key constraint。
任何想法我做错了什么?