drsdvwsvo78320812
drsdvwsvo78320812
2015-11-13 09:20

Laravel SQLSTATE [HY000] [1049]未知数据库'previous_db_name'

已采纳

I have this error when i use php artisan migrate in my Laravel project.

[PDOException]
SQLSTATE[HY000] [1049] Unknown database 'previous_db_name'

this is my database.php file :

'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'current_db_name'),
        'username'  => env('DB_USERNAME', 'root'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],
],

I saw this error in this question and this question but none of them was not helpful.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • dtvjl64442 dtvjl64442 6年前

    It clearly mentions that there's no such database named previous_db_name.

    From what it seems the database.php file is not where the variable is from.

    Check the .env file in your Laravel installation folder to see if that's the database name that you have wrongly specified.

    点赞 评论 复制链接分享
  • douji5746 douji5746 6年前

    In Laravel 5.x You should define the DB Details in two files

    1. .env file in the project folder
    2. .database.php file inside config folder
    点赞 评论 复制链接分享
  • douhuan1979 douhuan1979 2年前

    I know, it is super late but for people like me, new in laravel and following tutorial from artisansweb. Note that, migrate will not create your database. Rather, it will just create all the tables. Assuming, you have set up your .env file. Now the important part is create the database and users (if you decided to go with custom users) manually. Then, do the php artisan migrate command

    hope that helps.

    点赞 评论 复制链接分享
  • dtr87341 dtr87341 4年前

    set your database name in .env file too.

    点赞 评论 复制链接分享