我想用迁移做桌子, 但是当我执行时出现错误按摩
Incorrect table definition; there can be only one auto column and it must be defined as key
但是我没有将用户ID设置为增量和主键,为什么?
无论如何,我是初学者 这是我的代码
Schema::create('orders', function(Blueprint $table){
$table->increments('order_id');
$table->dateTime('order_date');
$table->integer('order_status')->default(0);
$table->integer('user_id', 10)->unsigned();
$table->string('npk_user_approval', 10);
$table->string('npk_ga_approval', 10);
$table->dateTime('approval_user_at')->nullable();
$table->dateTime('approval_ga_at')->nullable();
$table->dateTime('reject_user_at')->nullable();
$table->dateTime('reject_ga_at')->nullable();
$table->dateTime('created_at')->nullable();
$table->string('created_by', 50)->nullable();
$table->dateTime('updated_at')->nullable();
$table->string('updated_by', 50)->nullable();
$table->foreign('user_id')->references('id')->on('users');
});
答案 0 :(得分:1)
蓝图的integer()
方法的第二个参数是$autoIncrement?
。您正在传递10
,实际上它设置为自动增量。以下是从Blueprint
类:
/**
* Create a new integer (4-byte) column on the table.
*
* @param string $column
* @param bool $autoIncrement
* @param bool $unsigned
* @return \Illuminate\Support\Fluent
*/
public function integer($column, $autoIncrement = false, $unsigned = false)
{
return $this->addColumn('integer', $column, compact('autoIncrement', 'unsigned'));
}
所以不要传递10(你认为是大小),而是这样做:
$table->unsignedInteger('user_id');
相当于创建整数列,unsigned,autoIncrement已关闭。
要更改整数大小,请使用
等方法