我有以下迁移:
<?php
class Create_Users_Table {
/**
* Make changes to the database.
*
* @return void
*/
public function up()
{
Schema::create('users', function($table){
$table->increments('id');
$table->string('username');
$table->string('password');
$table->timestamps();
});
}
/**
* Revert the changes to the database.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
当我运行php artisan migrate
时,我收到以下错误:
Warning: PDO::__construct(): [2002] No connection could be made because the target machine actively (trying to connect via tcp://127.0.0.1:3306) in C:\xampp\htdocs\snip\laravel\database\connectors\mysql.php on line 33
Call Stack:
0.0007 326008 1. {main}() C:\xampp\htdocs\snip\artisan:0
0.0312 1527392 2. require('C:\xampp\htdocs\snip\laravel\cli\artisan.php') C:\xampp\htdocs\snip\artisan:24
0.0414 2067048 3. Laravel\CLI\Command::run() C:\xampp\htdocs\snip\laravel\cli\artisan.php:42
0.0448 2171864 4. Laravel\CLI\Tasks\Migrate\Migrator->run() C:\xampp\htdocs\snip\laravel\cli\command.php:49
0.0448 2171864 5. Laravel\CLI\Tasks\Migrate\Migrator->migrate() C:\xampp\htdocs\snip\laravel\cli\tasks\migrate\migrator.php:52
0.0448 2171928 6. Laravel\CLI\Tasks\Migrate\Resolver->outstanding() C:\xampp\htdocs\snip\laravel\cli\tasks\migrate\migrator.php:69
0.0448 2172368 7. Laravel\CLI\Tasks\Migrate\Database->ran() C:\xampp\htdocs\snip\laravel\cli\tasks\migrate\resolver.php:53
0.0448 2172368 8. Laravel\CLI\Tasks\Migrate\Database->table() C:\xampp\htdocs\snip\laravel\cli\tasks\migrate\database.php:61
0.0454 2209248 9. Laravel\Database::connection() C:\xampp\htdocs\snip\laravel\cli\tasks\migrate\database.php:81
0.0471 2287344 10. Laravel\Database::connect() C:\xampp\htdocs\snip\laravel\database.php:52
0.0482 2302840 11. Laravel\Database\Connectors\MySQL->connect() C:\xampp\htdocs\snip\laravel\database.php:66
0.0482 2305032 12. PDO->__construct() C:\xampp\htdocs\snip\laravel\database\connectors\mysql.php:33
SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
我在Win7和XAMPP上运行PHP 5.4。有什么我想念的吗?
编辑:这是database.php中的数据库配置:
'connections' => array(
...
'mysql' => array(
'driver' => 'mysql',
'host' => '127.0.0.1',
'database' => 'makeitsnappy',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
),
...
)
此外,目标计算机是我的本地服务器,我可以完全控制它。
答案 0 :(得分:0)
DB配置存在问题。检查您的dsn字符串或主机名和数据库驱动程序类型。