[英]Laravel 4 Migration - Cannot add foreign key constraint
Here's my migration code: 这是我的迁移代码:
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');
}
When the code to define the foreign key constraint is not commented out, I get the following error on the command line: General error: 1215 Cannot add foreign key constraint . 当没有注释掉定义外键约束的代码时,我在命令行上收到以下错误: 常规错误:1215无法添加外键约束 。
Any ideas what I am doing wrong? 我有什么想法我做错了吗?
$table->integer('foo_id')->unsigned;
should be 应该
$table->integer('foo_id')->unsigned();
or you can use short version: 或者您可以使用简短版本:
$table->unsignedInteger('foo_id');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.