-
-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrating Tenant Databases - Multi Database #27
Comments
try updating: |
Not working, same error occurred |
What is the output of |
Sorry, how can i get the output? |
Run |
what is the output of |
@wahyubaskara: try to change:
by
|
Solved! You saved me, thank you👍 |
Oh my word, this has been tripping me up! Is this in the docs? |
@kurucu, no, isn't in the docs because the default connection is a state of mind: depends on your project and your approach. |
hello spatie guys and @freekmurze
|
@Saimon-git, have you followed the documentation? |
thanks @masterix21 |
@refaatgamal are you using the SwitchDatabaseTask? |
Yes and now all tenants works well but I can't make landlord working but tenants works |
@refaatgamal, I'm sure it's a misconfiguration issue. Please dig inside reading our documentation. Thanks. |
Already working as docs but landlord didn't work how can I login as landlord I make virtual domains in local host for tenants but when I go to project direct with out tenant domain it gives me no database selected issue |
@refaatgamal got any solution on this issue? I'm trying to implement the laravel multitenancy and facing the same issue that you mentioned in your last comment. Thanks |
Sorry, but I still think that is a coding problem. Please create a GitHub repository with your sample code that generates the errors: I'll try to help asap. |
I am having the exact same problem after doing this: I can login to tenants but NOT to landlord account. getting the same error as: But when I switch the line back to: |
`'default' => 'tenant',
|
@masterix21 Is there a solution to this problem ? |
Please post your |
class Admin extends Authenticatable {
use Notifiable;
protected $table = 'admins';
protected $fillable = [
'email',
'name',
'photo_profile',
'password',
'group_id',
'remember_token',
];
protected $hidden = ['password'];
public function group_id() {
return $this->hasOne(\App\Models\AdminGroup::class, 'id', 'group_id');
}
public function role($name) {
$exists_group_id = $this->getConnection()
->getSchemaBuilder()
->hasColumn($this->getTable(), 'group_id');
if ($exists_group_id) {
$explode_name = explode('_', $name);
if (!empty($this->group_id()->first())) {
$role = $this->group_id()->first()->role()->where('name', $explode_name[0])->first();
if (!empty($role) && $role->{$explode_name[1]} == 'yes') {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
} |
SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected (SQL: select * from |
I created two databases and two domains in two domain I got this problem |
Admin model is in the landlord or in the tenant database? Why you didn't prepare your model? Take a look here: https://spatie.be/docs/laravel-multitenancy/v2/installation/using-multiple-databases#content-preparing-models
|
Ok I Will prepare the models |
@masterix21 unfortunately the same problem |
The open-source package philosophy lies in free cooperation: if you are here to search for an urgent solution, the best way is to dig inside the code to find it yourself. Anyway, please create a public GitHub repository with your code to help me to understand where your errors are. Thanks. |
ok |
@masterix21 I created new repo and I invited you |
@masterix21 protected static function booted()
{
static::creating(fn(User $model) => $model->createDatabase());
}
public function createDatabase()
{
// add logic to create database
DB::connection()->statement('CREATE DATABASE tenant_' . $this->username);
$this->database = 'tenant_' . $this->username;
Artisan::call('tenants:artisan migrate --tenant=' . $this->id);
} |
How can you call |
I've been follow all steps in the documentation, from creating landlord and tenant db connection then create a couple of rows in the tenants table with correct database name. After that i ran this command
php artisan tenants:artisan migrate
but the result always give me error:Invalid catalog name: 1046 No database selected
Full error message:
My database config:
My tenants table in landlord database:
My local databases:
My multitenancy.php config file:
The text was updated successfully, but these errors were encountered: