lundi 9 août 2021

Laravel migration works on Linux but not on windows

When I try to run my Laravel migration on windows this is the migration file that fails on Windows but works on Linux.

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTenantOwnerBridgeTable extends Migration
{
    /**
     * Schema table name to migrate
     * @var string
     */
    public $tableName = 'tenant_owner_bridge';

    /**
     * Run the migrations.
     * @table tenant_owner_bridge
     *
     * @return void
     */
    public function up()
    {
        Schema::create($this->tableName, function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->unsignedInteger('tenant_owner_id');
            $table->string('tenant_id', 191);
            $table->unsignedBigInteger('primary_admin_id');

            $table->index(["primary_admin_id"], 'fk_tenant_owner_bridge_user_id_idx');

            $table->index(["tenant_id"], 'fk_tenant_owner_bridge_tenant_id_idx');

            $table->index(["tenant_owner_id"], 'fk_tenant_owner_bridge_tenant_owner_id_idx');
            $table->nullableTimestamps();


            $table->foreign('tenant_id', 'fk_tenant_owner_bridge_tenant_id_idx')
                ->references('id')->on('tenants')
                ->onDelete('no action')
                ->onUpdate('no action');

            $table->foreign('tenant_owner_id', 'fk_tenant_owner_bridge_tenant_owner_id_idx')
                ->references('id')->on('tenant_owners_info')
                ->onDelete('no action')
                ->onUpdate('no action');

            $table->foreign('primary_admin_id', 'fk_tenant_owner_bridge_user_id_idx')
                ->references('id')->on('users')
                ->onDelete('no action')
                ->onUpdate('no action');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
     public function down()
     {
       Schema::dropIfExists($this->tableName);
     }
}

This is the error that is thrown. SQLSTATE[HY000]: General error: 1005 Can't create table primehybrid.tenant_owner_bridge (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table tenant_owner_bridge add constraint fk_tenant_owner_bridge_tenant_id_idx foreign key (tenant_id) references tenants (id) on delete no action on update no action)

Here is the table that the foreign key references.


<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateTenantsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up(): void
    {
        Schema::create('tenants', function (Blueprint $table) {
            $table->string('id')->primary();

            // your custom columns may go here

            $table->timestamps();
            $table->json('data')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down(): void
    {
        Schema::dropIfExists('tenants');
    }
}

Can someone explain why it works on Linux but not Windows and why it fails on Windows. Also see my list of migration files:

2012_08_06_000003_create_account_statuses_table.php
2013_08_06_000004_create_countries_table.php
**2014_10_12_000000_create_users_table.php**
2014_10_12_100000_create_password_resets_table.php
2016_06_01_000001_create_oauth_auth_codes_table.php
2016_06_01_000002_create_oauth_access_tokens_table.php
2016_06_01_000003_create_oauth_refresh_tokens_table.php
2016_06_01_000004_create_oauth_clients_table.php
2016_06_01_000005_create_oauth_personal_access_clients_table.php
2018_08_08_100000_create_telescope_entries_table.php
2019_08_19_000000_create_failed_jobs_table.php
**2019_09_15_000010_create_tenants_table.php**
2019_09_15_000020_create_domains_table.php
2020_04_06_222004_create_sessions_table.php
2020_05_15_000010_create_tenant_user_impersonation_tokens_table.php
2020_08_10_170933_create_jobs_table.php
2021_04_30_174805_create_cache_table.php
**2021_08_06_000000_create_tenant_owners_info_table.php**
2021_08_06_000001_create_secret_questions_table.php
2021_08_06_000006_create_recovery_info_table.php
**2021_08_06_000007_create_tenant_owner_bridge_table.php**
2021_08_06_223928_create_permission_tables.php


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire