tenancy: Unable to migrate multiple tenants at once when using MySQL
Hi,
I’ve write a CRUD controller to manage tenants.
After the creation phase I try to migrate database calling the related artisan command in this way:
\Artisan::call('tenants:migrate', [ '--tenants' => [$tenant['uuid']] ]);
but the process fail with an exception
Symfony \ Component \ Console \ Exception \ CommandNotFoundException The command “tenants:migrate” does not exist.
Then to resolve this issue I’ve clone the command in the App\Console\Commands directory. When I run the creation process from controller the tenants()->create(‘sub.domain’) command create the tenant and create the database but fail running the migration with this exception
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'tenant51fc8900-bd14-11e9-812f-bf18d2921640.migrations' doesn't exist (SQL: select
migrationfrom
migrationsorder by
batchasc,
migration asc)
I noticed that the problem occur also when I run the migration for all tenants from the terminal `php artisan tenants:migrate Tenant: 0263c840-ba6c-11e9-801a-a932495b9d33 (marco.itplog.com) Nothing to migrate. Tenant: dabfa100-bce9-11e9-8818-c51ed3718fe9 (umb.itplog.com)
Illuminate\Database\QueryException : SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘tenantdabfa100-bce9-11e9-8818-c51ed3718fe9.migrations’ doesn’t exist (SQL: select migration
from migrations
order by batch
asc, migration
asc)
at /home/vagrant/Code/rat/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664 660| // If an exception occurs when attempting to run a query, we’ll format the error 661| // message to include the bindings with SQL, which will make this exception a 662| // lot more helpful to the developer instead of just the database’s errors. 663| catch (Exception $e) {
664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| } 668|
Exception trace:
1 PDOException:😦"SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘tenantdabfa100-bce9-11e9-8818-c51ed3718fe9.migrations’ doesn’t exist") /home/vagrant/Code/rat/vendor/laravel/framework/src/Illuminate/Database/Connection.php:326
2 PDO::prepare(“select migration
from migrations
order by batch
asc, migration
asc”)
/home/vagrant/Code/rat/vendor/laravel/framework/src/Illuminate/Database/Connection.php:326
Please use the argument -v to see more details.`
But no errors when I run from terminal the single tenant migration
php artisan tenants:migrate --tenants=dabfa100-bce9-11e9-8818-c51ed3718fe9 Tenant: dabfa100-bce9-11e9-8818-c51ed3718fe9 (umb.itplog.com) Migration table created successfully.
How can I resolve this blocking issue?
Thanks
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 28 (12 by maintainers)
Hi.
Strange issue. I can’t reproduce this.
php artisan tenants:migrate
works ok for me with multiple tenants:What version are you using? Try running
composer update
.Can you try reproducing this in a fresh Laravel install?