我已将所有整数设为无符号但我仍然收到错误。我需要改变什么?
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateFacebook extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('facebook', function($table)
{
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
$table->timestamps();
$table->string('username', 255);
$table->bigInteger('uid', 20)->unsigned();
$table->string('access_token', 255);
$table->string('access_token_secret', 255);
$table->string('photoURL', 255);
$table->string('profileURL', 255);
$table->string('firstName', 255);
$table->string('lastName', 255);
$table->string('gender', 255);
$table->string('age', 20);
$table->integer('birthDay')->unsigned();
$table->integer('birthMonth')->unsigned();
$table->integer('birthYear')->unsigned();
$table->string('email', 255);
$table->string('phone', 30);
$table->string('address', 255);
$table->string('country', 100);
$table->string('region', 100);
$table->string('city', 100);
$table->string('zip', 20);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('facebook');
}
}
SQLSTATE [42000]:语法错误或访问冲突:1075表定义不正确;只能有一个自动列,必须将其定义为键
谢谢。
答案 0 :(得分:26)
使用
$table->bigInteger('uid')->unsigned();
而不是
$table->bigInteger('uid', 20)->unsigned();
<强>的相关信息:强>
在/vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint
中你可以看到bigInteger函数:
public function bigInteger($column, $autoIncrement = false, $unsigned = false)
20(不是0)对true
的贬义。
虽然string
方法有第二个参数length
:
public function string($column, $length = null)
因此,如果您使用任何整数蓝图(bigInteger
,mediumInteger
,tinyInteger
,smallInteger
等...)与任何第二个参数(非0)您告诉Laravel使用auto_increment
属性创建一个整数,这将返回:
Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key")
答案 1 :(得分:2)
通过以下方法为bigInteger列指定大小
$table->bigInteger('uid')->length(20)->unsigned();