Laravel Migrations - Table Prefix Issue

自作多情 提交于 2019-12-04 17:11:03

In application->config->database.php set the prefix as follows

'mysql' => array(
'driver'   => 'mysql',
'host'     => 'localhost',
'database' => 'foodb',
'username' => 'root',
'password' => '',
'charset'  => 'utf8',
'prefix'   => 'ula_',       <-- this is where you need to set the table prefix
),

After setting this, migrate:reset and migrate it again I have done this way and its works perfect

On Laravel 5.4.*, I ended up creating the artisan command to add table prefix on a few tables using below handle method.

public function handle()
{
    $this->tablePrefix = 'tmp_';

    // Set table prefix
    DB::setTablePrefix($this->tablePrefix);

    $data = [
        '--path' => [
            'database/prefixed-migrations' // Directory Path to migrations which require table prefix 
        ],
        '--database' => 'cli',
        '--force' => true
    ];

    $this->call('migrate', $data); // Next call the migration

    Model::reguard();
}

Hope this helps if anyone looking to prefix on certain tables without setting it globally.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!