语法错误或访问冲突:1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not n

Syntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not n

一切正常,直到我开始使用 users tables id 作为 blogs table 中的外键并尝试将其迁移到数据库中。我开始收到

的错误

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right synt ax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not n' at line 1 (SQL: create table blogs (id int unsigned not null auto_increment primary key, user_id varchar(191) unsigned not null, modelName varchar(191) not null, title varchar(191) not null, price int unsigned not null, description text not n ull, status int not null, photo_id varchar(191) not null, company_id varchar(191) not null default '1', created_at timestamp null, updated_at timestamp null) default c haracter set utf8mb4 collate utf8mb4_unicode_ci) In Connection.php line 445: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right synt ax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not n' at line 1**

这里是用户table结构

public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('role_id')->index()->unsigned()->nullable();
            $table->integer('is_active')->default(0);
            $table->string('name');
            $table->string('photo_id')->default('default.png');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

这是博客 table 结构

 public function up()
    {
        Schema::create('blogs', function (Blueprint $table) {
            $table->increments('id');
            $table->string('user_id')->unsigned();
            $table->string('modelName')->index();
            $table->string('title');
            $table->integer('price')->unsigned();
            $table->text('description')->nullable(false);
            $table->integer('status');
            $table->string('photo_id');
            $table->string('company_id')->default(!null);
            $table->timestamps();

//            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('user_id')->refrences('id')->on('users');

        });
    }

我几乎尝试了所有可能出错的方法,也尝试了在线提供的解决方案,但目前似乎没有任何效果。任何帮助将不胜感激。

$table->string('user_id')->unsigned();

string 类型的字段不能未签名。更改为

$table->integer('user_id')->unsigned();