I have made all integers unsigned but I still get the error. What do I need to change?
<?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
Thank you.
Use
$table->bigInteger('uid')->unsigned();
instead of
$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")
Specify the size for bigInteger column by following way
$table->bigInteger('uid')->length(20)->unsigned();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With