Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mesasix's avatar

Database Migrations in Lumen with Multiple Database Connections

So i setup multiple database connections in config/database.php:

return [
    'default' => 'trd_admin',

    'connections' => [
        'trd_admin' => [
            'driver'    => env('DB_CONNECTION'),
            'host'      => env('DB_HOST'),
            'port'      => env('DB_PORT'),
            'database'  => env('DB_DATABASE'),
            'username'  => env('DB_USERNAME'),
            'password'  => env('DB_PASSWORD'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false
        ],

        'local' => [
            'driver'    => env('LOCAL_CONNECTION'),
            'host'      => env('LOCAL_HOST'),
            'port'      => env('LOCAL_PORT'),
            'database'  => env('LOCAL_DATABASE'),
            'username'  => env('LOCAL_USERNAME'),
            'password'  => env('LOCAL_PASSWORD'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false
        ]
    ]
];

and when I run:

php artisan migrate:install --database=local

it gives me this errors:

[Illuminate\Database\QueryException]                                         
SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name '' (SQL: create table `` (`migration` varchar(255) not null, `batch` int not null) default character set utf8 collate utf8_unicode_ci)  
[PDOException]                                                               
SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name '' 

Thanks for your reply.

0 likes
6 replies
mesasix's avatar

thanks for the reply @bobbybouwmann

i dont have any migrations yet. the command:

php artisan migrate:install --database=local

simply tries to create a new migration database table and it failed already.

So I cant proceed in creating the migrations for my tables.

bobbybouwmann's avatar

Create one migration and the try to run php artisan migrate --database=local

mesasix's avatar

hi @bobbybouwmann, thanks for taking time to look into this.

yeah i already tried

php artisan migrate --database=local

but still gives me the same sets of errors above. I even restarted homestead and re-provision homestead.

As you can see on the error, it tries to create a table with empty name. I guess this has something to do with multiple database connections with lumen.

Weird thing though is that when I deleted the config/database.php file, I can run all my migrations using the default DB connections on .env file.

bobbybouwmann's avatar

Mmh that's odd.. Create an issue on Github, they might know an answer ;)

giviz's avatar
giviz
Best Answer
Level 3

If anyone has the same problem like I just did, here is a valid solution :

https://github.com/laravel/lumen-framework/issues/248

You need to declare the migration entry is the database config

<?php

return [

    'default' => 'external',
    'migrations' => 'migrations',
    'connections' => [
        // your connections
    ],
];
1 like

Please or to participate in this conversation.