我可以';t做外键,约束错误


I can't do a foreign key, constraint error

我有一个commum错误,我无法查看它,因为[Illuminate'Database'QueryException] SQLSTATE[42000]这里是完整的错误:

[IIlluminate''Database''QueryException]SQLSTATE[42000]:语法错误或访问违规:1064您的SQL语法有错误;检查与MySQL服务器版本对应的手册在第1行使用接近"unsigned null"的正确语法(SQL:alter表files添加slug varchar(255)无符号空)

一个单独的错误:

[PDOException]SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;查看手册与您的MySQL服务器版本相对应,以便使用正确的语法第1行接近"unsigned null"

他是我正在努力做的表外键:

文件

  public function up()
    {
        Schema::create('files', function($table)
        {
            $table->engine = 'InnoDB';
            $table->increments('id')->unsigned();
            $table->string('name')->nullable();
            $table->boolean('enable_sch')->nullable();
            $table->datetime('schdate')->nullable();
            $table->string('flsize')->nullable();
            $table->timestamps();
        });
        Schema::table('files', function($table)
        {
          $table->string('slug')->unsigned()->nullable();
          $table->foreign('slug')->references('slug')->on('slugs');
        });
    }

段塞

public function up()
    {
        Schema::create('slugs', function($table)
        {
            $table->engine = 'InnoDB';
            $table->string('nameslug');
            $table->string('slug')->unsigned()->nullable();
            $table->timestamps();
        });
    }
    public function down()
    {
        Schema::dropIfExists('slugs');
    }

我想做的是将slugs table中的*slug column*添加到files table中。

我想string的数据类型不能是unsigned(),这就是为什么会出现错误。

在两次迁移中都使用此选项:

$table->string('slug')->nullable();

由于我将OctoperCMS与Laravel一起使用,**models** file上有类似$hasMany$belongsTorelationships 

如果在OctoberCMS上遇到问题,只需咨询此