我已经使所有整数都无符号,但我仍然得到错误.我需要改变什么?

<?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]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be de fined as a key

非常感谢.

推荐答案

使用

$table->bigInteger('uid')->unsigned();

而不是

$table->bigInteger('uid', 20)->unsigned();

Infos:

in /vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint you can see the bigInteger function:

public function bigInteger($column, $autoIncrement = false, $unsigned = false)

So 20 (not being 0) evals to true.

While string method has as second parameter length:

public function string($column, $length = null)

Therefore if you use any integer blueprint (bigInteger, mediumInteger, tinyInteger, smallInteger, etc...) with any second parameter (other than 0) you are telling Laravel to make an integer with an auto_increment property, this will return:

Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key")

Laravel相关问答推荐

为什么我的 Laravel 开发服务器不提供 public 文件夹下的文件?

"public/index.php" 可以在 laravel 中按组写入

语法错误或访问冲突:1115 未知字符集:utf8mb4

我在哪里放置事件侦听器和处理程序?

.gitignore 不忽略文件夹

在Laravel 5中通过ID和所有递归获取记录

Laravel 使用 Storage::put 生成唯一 ID

如何更改 ember-cli 中的 dist 文件夹路径?

在 laravel 分页中添加一些数据

Laravel 动作未定义

使用 Laravel 将两个模型合并到一个分页查询中,并带有Eager加载的关系

命令未定义异常

Laravel 迁移 - 删除列

在 Laravel 5.4 中向多个抄送收件人发送Electron邮件

改变模式生成器中的列长度?

Laravel 接口

找不到框laravel/homestead

在 laravel 的自定义路径中创建模型

如何在 Laravel 中 Refresh刷新用户对象?

限制自己重载外部 API 的速率