Laravel 5.6 | PHP工匠迁移不起作用

时间:2018-04-14 18:24:45

标签: php laravel macos mamp

我在搜索这个问题时已经尝试过很多事情,但是对我来说什么都没有用。

我正在使用MAMP运行Mac OS 10.13.4。此命令适用于带有XAMPP的Windows机器。

我尝试的事情:

  • 在`.env`
  • 中将`127.0.0.1`更改为`localhost`
  • 在`.env`中将`DB_PORT`从`3306`改为`8889`
  • 添加:`' unix_socket' => ' /tmp/mysql.sock'`,到`config \ database.php`

以下是将php artisan migrate -v输入终端后返回的内容。

SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = b_rowland and table_name = migrations)

  at /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php: 664
  660:         // If an exception occurs when attempting to run a query, we'll format the error
  661:         // message to include the bindings with SQL, which will make this exception a
  662:         // lot more helpful to the developer instead of just the database's errors.
  663:         catch (Exception $e) {
  664:             throw new QueryException(
  665:                 $query, $this->prepareBindings($bindings), $e
  666:             );
  667:         }
  668: 
  669:         return $result;

  Exception trace:

  1   PDOException::("SQLSTATE[HY000] [2002] No such file or directory")
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php : 68

  2   PDO::__construct("mysql:unix_socket=/tmp/mysql.sock;dbname=b_rowland", "root", "", [])
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php : 68

  3   Illuminate\Database\Connectors\Connector::createPdoConnection("mysql:unix_socket=/tmp/mysql.sock;dbname=b_rowland", "root", "", [])
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php : 44

  4   Illuminate\Database\Connectors\Connector::createConnection("mysql:unix_socket=/tmp/mysql.sock;dbname=b_rowland", [])
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php : 24

  5   Illuminate\Database\Connectors\MySqlConnector::connect()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php : 183

  6   Illuminate\Database\Connectors\ConnectionFactory::Illuminate\Database\Connectors\{closure}()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 915

  7   call_user_func(Object(Closure))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 915

  8   Illuminate\Database\Connection::getPdo()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 940

  9   Illuminate\Database\Connection::getReadPdo()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 399

  10  Illuminate\Database\Connection::getPdoForSelect()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 325

  11  Illuminate\Database\Connection::Illuminate\Database\{closure}("select * from information_schema.tables where table_schema = ? and table_name = ?")
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 657

  12  Illuminate\Database\Connection::runQueryCallback("select * from information_schema.tables where table_schema = ? and table_name = ?", Object(Closure))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 624

  13  Illuminate\Database\Connection::run("select * from information_schema.tables where table_schema = ? and table_name = ?", Object(Closure))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 333

  14  Illuminate\Database\Connection::select("select * from information_schema.tables where table_schema = ? and table_name = ?")
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Schema/MySqlBuilder.php : 18

  15  Illuminate\Database\Schema\MySqlBuilder::hasTable("migrations")
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php : 169

  16  Illuminate\Database\Migrations\DatabaseMigrationRepository::repositoryExists()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php : 545

  17  Illuminate\Database\Migrations\Migrator::repositoryExists()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php : 97

  18  Illuminate\Database\Console\Migrations\MigrateCommand::prepareDatabase()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php : 63

  19  Illuminate\Database\Console\Migrations\MigrateCommand::handle()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php : 29

  20  call_user_func_array([])
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php : 29

  21  Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php : 87

  22  Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Object(Closure))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php : 31

  23  Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), [])
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Container/Container.php : 564

  24  Illuminate\Container\Container::call()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Console/Command.php : 183

  25  Illuminate\Console\Command::execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/symfony/console/Command/Command.php : 252

  26  Symfony\Component\Console\Command\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Console/Command.php : 170

  27  Illuminate\Console\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/symfony/console/Application.php : 865

  28  Symfony\Component\Console\Application::doRunCommand(Object(Illuminate\Database\Console\Migrations\MigrateCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/symfony/console/Application.php : 241

  29  Symfony\Component\Console\Application::doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/symfony/console/Application.php : 143

  30  Symfony\Component\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Console/Application.php : 88

  31  Illuminate\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php : 122

  32  Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/artisan : 37

7 个答案:

答案 0 :(得分:1)

在.env文件中,关于数据库配置,是否已填写所有设置?

这是环境变量:

DB_CONNECTION=
DB_HOST=
DB_PORT=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=

此外,如果您要使用mysql sock,则需要DB_SOCKET = /mysql.sock

答案 1 :(得分:0)

尝试使用更改环境。

 php artisan migrate --env=dev

答案 2 :(得分:0)

我使用XAMPP处理MacOS并且必须将其添加到.env文件中: DB_SOCKET=/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

答案 3 :(得分:0)

白痴回答,但仍然是一个答案。
在MAMP&amp ;;上将我的服务器端口从3306更改为4444 Laravel .env。
奇怪的是,我尝试过的所有其他端口都没有用。希望这有助于其他人。

答案 4 :(得分:0)

这应该适合您!

转到项目中app文件夹的Providers目录中的public class Function { public static Func<IServiceProvider> ConfigureServices = () => { var serviceCollection = new ServiceCollection(); serviceCollection.AddOptions(); //OPTIONAL //...add additional services as needed //building configuration var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddEnvironmentVariables() .Build(); //Get strongly typed setting from appsettings binding to object graph var settings = configuration.Get<AppSettings>(); // adding to service collection so that it can be resolved/injected as needed. serviceCollection.AddSingleton(settings); return serviceCollection.BuildServiceProvider(); } static IServiceProvider services; static Function() { //Static ctor invokes once. services = ConfigureServices(); } public string FunctionHandler(string input, ILambdaContext context) { //... var settings = services.GetRequiredService<AppSettings>(); var message = settings.Message; return message; } } 文件。例如AppServiceProvider.php

然后输入以下内容:

C:\xampp\htdocs\projectName\app\providers\AppServiceProvider.php

还要在同一文件中,将启动功能编辑为这种格式。

use Illuminate\Support\Facades\Schema;

答案 5 :(得分:0)

尝试在您的终端中执行此操作:

 php artisan migrate --env=dev

答案 6 :(得分:0)

遇到了类似的问题,我无法执行 artisan 命令,并且 composer Update 和 dump-autoload 命令返回错误“Script @php artisan package:discover --ansi 处理 post-autoload-dump 事件返回错误代码 255 "

就我而言,问题既不是作曲家也不是工匠命令,而是由于在处理 Exceptions/Handler.php 文件时放错了 } 而导致的错误。我建议检查最近对默认 Laravel 文件的任何修改。希望这可以帮助某人。快乐编码。