When I create a migration for table at that time there is an issue with its through following error.
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1005 Can't create table
yourwebs_veridocedu
.#sql-2c46_8e
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter tableuser_role_mappings
add constraintuser_role_mappings_user_id_foreign
foreign key (user_id
) referencesusers
(id
) on delete cascade)
Migration for userrolemapping table:
public function up()
{
Schema::create('user_role_mappings', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('group_id');
$table->integer('roleid');
$table->integer('status');
$table->integer('createdby');
$table->integer('modifiedby');
$table->string('publicguid');
$table->string('privateguid');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade');
});
}
Migration for Role table :
public function up()
{
Schema::create('userroles', function (Blueprint $table) {
$table->increments('id');
$table->string('rolename');
$table->integer('status')->default(1);
$table->integer('createdby')->default(1);
$table->integer('modifiedby')->default(1);
$table->string('publicguid');
$table->string('privateguid');
$table->timestamps();
});
}
FK in table is not working which migrate.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire