Php 什么';Laravel外键有什么问题?

Php 什么';Laravel外键有什么问题?,php,mysql,laravel,Php,Mysql,Laravel,我正在尝试使用Laravel的迁移创建外键 Schema::create('articles', function (Blueprint $table) { $table->increments('id'); $table->integer('user_id')->unsinged(); $table->string('title'); $table->longText('body');

我正在尝试使用Laravel的迁移创建外键

 Schema::create('articles', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id')->unsinged();
        $table->string('title');
        $table->longText('body');
        $table->timestamp('published_at');
        $table->timestamps();

    });


    Schema::table('articles', function($table) {
        $table->foreign('user_id')
            ->references('id')
            ->on('users')
            ->onDelete('cascade');

    });
当我执行
php artisan迁移时,我遇到以下错误

[照亮\数据库\查询异常]
SQLSTATE[HY000]:一般错误:1215无法添加外键约束 (SQL:alter TABLE
laravel\u articles
add constraint 文章\u user\u id\u外键(
user\u id
)参考
laravel\u用户
id
)在删除级联上)`


方法名称中有一个输入错误。它应该是
unsigned()
而不是
unsigned()


模式生成器使用链接方法,即使链接方法
unsinged
不存在,也不会引发异常。尽管键入错误,
articles
表仍将被创建,但是
user\u id
列将是一个有符号整数,并且由于
users
表中的
id
列是一个无符号整数,因此将阻止创建约束。

方法名称中存在键入错误。它应该是
unsigned()
而不是
unsigned()


模式生成器使用链接方法,即使链接方法
unsinged
不存在,也不会引发异常。尽管输入错误,
articles
表仍将被创建,但是
user\u id
列将是一个有符号整数,并且由于
users
表中的
id
列是一个无符号整数,因此将阻止创建约束。

@MarkBaker不起作用!!这是相同的迁移吗?@MarkBaker不起作用!!这是相同的迁移吗?
Schema::create('articles', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('user_id')->unsigned();
    $table->string('title');
    $table->longText('body');
    $table->timestamp('published_at');
    $table->timestamps();
});