I created this migration script, but it gives the following error. It wont give any error if I changed the data type of the another column to string or something else. How to solve this issue?
Schema::create('incidents', function (Blueprint $table) {
$table->string('id');
$table->primary('id');
$table->unsignedInteger('user_id', 255);
});
SQLSTATE[42000]: Syntax error or access violation: 1068 Multiple primary key defined (SQL: alter table
incidentsadd primary keyincidents_id_primary(id))
SQLSTATE[42000]: Syntax error or access violation: 1068 Multiple primary key defined
Edit
Because nothing is working I moved this user_id creation to another migration script. Now it still fails to run the second migration script. Gives this error:
Syntax error or access violation: 1068 Multiple primary key defined (SQL: alter table
incidentsadduser_idint unsigned not null auto_increment primary key)
It seems, if the primary key is not integer, then Laravel tries to make next first integer column primary!!!
So my first script is,
public function up()
{
Schema::create('incidents', function (Blueprint $table) {
$table->string('id')->primary();
});
}
Second script is,
public function up()
{
Schema::table('incidents', function($table) {
$table->unsignedInteger('user_id', 255);
});
}
UPDATED
Make it like this:
And dont forget to add on your model
Problem
Acording to laravel docs
The function you use receives a bool as parameter and the number 255 was being interpreted as true. I think the DB makes the autoIncrement a
primary_key