My Laravel migration is like below
public function up()
{
Schema::create('account_main', function (Blueprint $table) {
$table->increments('user_sn')->primary();
$table->string('member_username', 20);
$table->string('login_password', 255);
$table->integer('login_count')->default('0')->unsigned();
});
}
When I ran php artisan migrate
, it shows the following error:
1068 Multiple primary key
Could someone help to find the problem?
In Laravel Eloquent ORM
the type increments
will be defined as primary key
automatically. So don't need to use primary()
method.
If the column is integer.
$table->increments('user_sn');
If the column is string
$table->string('user_sn')->primary();
If you want any other column to be unique (instead of primary key)
$table->increments('user_sn');
$table->string('member_username', 20)->unique(); // cannot contain duplicate values