Laravel 5.0, migration: how to make an integer non-primary?

I would like to move the table with the elements below.

public function up() { Schema::create('users', function(Blueprint $table) { $table->increments('id'); $table->integer('LoginID', 9)->unsigned(); $table->string('username'); $table->string('email')->unique(); $table->string('password', 60)->unique(); $table->rememberToken(); $table->timestamps(); }); } 

However, I continued to deal with the error below. Does anyone know how to make the integer "LoginID" and not the primary key so that I can wrap the table below? Any advice appreciated. Thanks in advance.

[Lighten \ Database \ QueryException]
SQLSTATE [HY000]: general error: 1 users table has more than one primary key (SQL: create a users table (id id integer, not null primary key auto-increment, LoginID integer, not null primary key auto-increment, "username" "varchar not null," email "varchar not null," password "varchar not null," remember_token "varchar null," created_at "date is not null," updated_at "datetime is not null))

+5
source share
3 answers

The problem is that you are using the function ->integer() with the second parameter. According to docs , the second parameter expects the boolean to be set to auto-increment or not: bool $autoIncrement = false ).

Try the following:

 public function up() { Schema::create('users', function(Blueprint $table) { $table->increments('id'); $table->integer('LoginID')->unsigned(); $table->string('username'); $table->string('email')->unique(); $table->string('password', 60)->unique(); $table->rememberToken(); $table->timestamps(); }); } 
+4
source

try it

 $table->integer('company_tel')->length(10)->unsigned(); 

or

 $table->integer('company_tel', false, true)->length(10); 

Read more https://laracasts.com/discuss/channels/general-discussion/why-am-i-getting-a-database-error-on-migration

+1
source

Is it possible to call

 $table->primary('id'); 

to mark id column as primary key?

0
source

Source: https://habr.com/ru/post/1246271/


All Articles