Laravel Migration - Says unknown database, but it is created

北战南征 提交于 2020-01-05 12:09:11

问题


when I use php artisan migrate, i get the error SQLSTATE[42000] [1049] Unknown database 'databaseName'.

But the database DOES exists! I even tried going back into terminal, logged into mysql and created the database again, and it said that database already exists!

Why is this giving me this error?


回答1:


In your app/config/database.php file change the default value from databaseName to a real database name that you are trying to use in your application, something like this (for mysql driver):

'mysql' => array(
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'your database name', //<-- put the database name
    'username'  => 'your user name',
    'password'  => 'your password',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
),



回答2:


I have the same problem. When I run: php artisan migrate. In my case I use Vagrant with scotch box.

To solve this, enter:

  1. vagrant ssh
  2. cd /var/www/yourproject
  3. php artisan migrate

And all work well.




回答3:


One thing could be your casing. If you read the docs on case sensitivity it says:

the case sensitivity of the underlying operating system plays a part in the case sensitivity of database and table names. This means database and table names are not case sensitive in Windows, and case sensitive in most varieties of Unix. One notable exception is Mac OS X, which is Unix-based but uses a default file system type (HFS+) that is not case sensitive.

Then go and check your application database setting found @ app/config/database.php.

Something that looks like this:

'mysql' => array(
    'read' => array(
        'host' => '192.168.1.1',
    ),
    'write' => array(
        'host' => '196.168.1.2'
    ),
    'driver'    => 'mysql',
    'database'  => 'databaseName',
    'username'  => 'root',
    'password'  => '',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
),

And double check everything.

Also try using snake_case rather than camelCase for you database name.



来源:https://stackoverflow.com/questions/22750995/laravel-migration-says-unknown-database-but-it-is-created

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