Php 拉拉维尔移民赢得';t添加整数类型的外键(mysql)

Php 拉拉维尔移民赢得';t添加整数类型的外键(mysql),php,mysql,database,laravel,laravel-4,Php,Mysql,Database,Laravel,Laravel 4,我试图添加一个引用引用表中整数主键的foregin键。laravel创建表的方式面临两个问题:第一个问题是,如果我尝试显式输入外键列整数长度11以匹配引用列,它会认为我希望该列作为主键?我得到了一个错误: "Incorrect table definition; there can only be one auto column and it must be defined as a key" 即使我将主键显式声明为“id”列,也会出现此错误。下面是我用来产生此错误的代码: publi

我试图添加一个引用引用表中整数主键的foregin键。laravel创建表的方式面临两个问题:第一个问题是,如果我尝试显式输入外键列整数长度11以匹配引用列,它会认为我希望该列作为主键?我得到了一个错误:

"Incorrect table definition; there can only be one auto column and it must be defined as a key"
即使我将主键显式声明为“id”列,也会出现此错误。下面是我用来产生此错误的代码:

    public function up()
{
    Schema::create('ip_bans', function(Blueprint $table)
        {
            $table->increments('id');
            $table->string('ip_address', 255);
            $table->integer('ban_id', 11);
            $table->primary('id');
            $table->foreign('ban_id')->references('id')->on('user_bans')->onDelete('set null');
        });
}
以下是参考表的模式:

    public function up()
{
    Schema::create('user_bans', function(Blueprint $table)
        {
            $table->increments('id');
            $table->string('reason');
            $table->string('banned_user', 16);
            $table->timestamps();
            $table->timestamp('ban_end');
            $table->foreign('banned_user')->references('username')->on('users')->onDelete('cascade');
        });
}
如果从外键列中删除显式整数长度11,则无法创建外键,因为列的长度为11,而“user_bans”表中的引用列为10,因此列不匹配。这里有什么我做错了的吗?或者有什么方法可以避免这个错误吗?

你试过吗

$table->integer('ban_id', 11)->unsigned;

(注意本节下面的粉红色框)

目前它是一个方法:->unsigned();