Search code examples
multi-tenantlaravel-8laravel-livewire

Spatie Laravel-multitenancy run migrate command after tenant create error


I am using Spatie Laravel-multitenancy . With the following code i am creating a new tenant, then a database and after that using the artisan command provied by the package to migrate the particular tenant database. Everything is working fine . Tenant , database even migration has been done . But after that it shows error as below.

Mycode

try {
        if ($this->isTenantExists($this->domain)) {
            throw new Exception("Error Processing Request", 1);
        }
        $tenant = Tenant::create([
            'name' => $this->name,
            'domain' => $this->domain,
            'database' => $this->database,
        ]);
        if ($this->isDatabaseExists($this->database)) {
            throw new Exception("Error Processing Request", 1);
        }
        $charset = config("database.connections.mysql.charset", 'utf8mb4');
        $collation = config("database.connections.mysql.collation", 'utf8mb4_unicode_ci');
        config(["database.connections.mysql.database" => null]);
        $query = "CREATE DATABASE IF NOT EXISTS $this->database CHARACTER SET $charset COLLATE $collation;";
        DB::statement($query);
        Artisan::call("tenants:artisan migrate --tenant={$tenant->id}");
    } catch (\Throwable $th) {
        Log::error($th);
    }

enter image description here


Solution

  • It was a session_driver issue. It works when i changed session driver to file on env file.