问题
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:
- vagrant ssh
- cd /var/www/yourproject
- 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