问题现象
新手在执行php artisan migrate时可能会出现这个错误。
解决方法
在想要加外键的地方添加方法->unsigned()即可。
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->string('flag');
$table->string('title');
$table->integer('category_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->text('content');
$table->text('markdown');
$table->integer('views');
$table->integer('comments');
$table->timestamp('deleted_at');
$table->timestamps();
$table->foreign('category_id')->references('id')->on('categories');
$table->foreign('user_id')->references('id')->on('users');
});
}