语法错误或访问冲突:1064:在'unsigned not null附近使用的语法,modelName varchar(191)not null,title varchar(191)not n

DaS*_*Sid 2 php database migration phpmyadmin laravel-5.4

一切都工作正常,直到我开始usersblogs表中使用表id作为外键并尝试将其迁移到数据库中.我开始得到错误

SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误; 检查与您的MariaDB服务器版本对应的手册,以便在第1行使用'unsigned not null,modelNamevarchar(191)not null,titlevarchar(191)not n' 附近使用正确的SYN ax (SQL:create table blogs(idint unsigned not null) auto_increment主键,user_idvarchar(191)unsigned not null,modelNamevarchar(191)not null,titlevarchar(191)not null,priceint unsigned not null,descriptiontext not n ull,statusint not null,photo_idvarchar(191)not null,company_idvarchar(191 )not null default'1 ',created_attimestamp null,updated_attimestamp null)default c haracter set utf8mb4 collat​​e utf8mb4_unicode_ci)在Connection.php第445行:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误; 查看与您的MariaDB服务器版本对应的手册,以便在第1行使用'unsigned not null,modelNamevarchar(191)not null,titlevarchar(191)not n' 附近使用正确的合成器

这是users表结构

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();
        });
    }
Run Code Online (Sandbox Code Playgroud)

这是博客表结构

 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');

        });
    }
Run Code Online (Sandbox Code Playgroud)

我已经尝试了几乎所有可能出错的知识,并尝试了在线提供的解决方案,但现在似乎没有任何工作.任何帮助将受到高度赞赏.

ker*_*olz 6

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

类型的字段string不能是无符号的.改成

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

  • 这是"引用",而不是"引用".睡一觉;)(也许接受这个答案) (2认同)