When I changed my primary key from increments to string (user_id) i now got an error in my migrations. I dont seem to see where I went wrong. my migrations files were okay until I changed from (->increments and the other one ->integer) to (->string on both). The problem is when it migrates clanmembers table, it says foreign key is incorrectly formed
My code before. Seem to be okay, nothing wrong with the migration in cmd
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('user_id');
$table->string('fname', 50);
$table->string('lname', 50);
$table->integer('age');
$table->string('gender', 10);
$table->string('address', 50);
$table->timestamps();
});
}
public function up()
{
Schema::create('clanmembers', function (Blueprint $table) {
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('user_id')->on('users')->onDelete('cascade');
$table->integer('clan_id')->unsigned();
$table->foreign('clan_id')->references('clan_id')->on('clans')->onDelete('cascade');
$table->string('bandrole', 50);
$table->timestamps();
});
}
My code now after I changed ->increments and ->integer into both ->string
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->string('user_id');
$table->string('fname', 50);
$table->string('lname', 50);
$table->integer('age');
$table->string('gender', 10);
$table->string('address', 50);
$table->timestamps();
});
}
public function up()
{
Schema::create('clanmembers', function (Blueprint $table) {
$table->string('user_id');
$table->foreign('user_id')->references('user_id')->on('users')->onDelete('cascade');
$table->integer('clan_id')->unsigned();
$table->foreign('clan_id')->references('clan_id')->on('clans')->onDelete('cascade');
$table->string('clanrole', 50);
$table->timestamps();
});
}