Laravel homestead: Unknown database 'projectadmin_db'

帅比萌擦擦* 提交于 2019-12-10 23:34:53

问题


I am new to laravel. I use homestead for development. I have two database connection

database.php

'cust_main_db'   =>  [
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'database'  => 'project_db',
        'username'  => 'homestead',
        'password'  => 'secret',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],
    'admin_main_db'   =>  [
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'database'  => 'projectadmin_db',
        'username'  => 'homestead',
        'password'  => 'secret',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

Homestead.yaml

databases:
    - homestead

In my local mysql has both databases project_db and projectadmin_db

When I run the project http://homestead.app:8000/ it shows SQLSTATE[HY000] [1049] Unknown database 'projectadmin_db'

What I have missed here? Correct me if anything wrong.


回答1:


When you run your app in Homestead, it looks for databases in Homestead and not your actual localhost. You can connect to Homestead's MySQL through 127.0.0.1:33060.




回答2:


On models that use projectadmin_db database, you need to add

protected $connection = 'admin_main_db';



回答3:


make sure you use the default Homestead port 33060 , when you are creating your databases ,

i.e: you created your databases on the guest vm not on the host machine.



来源:https://stackoverflow.com/questions/32756810/laravel-homestead-unknown-database-projectadmin-db

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