不能将migrate与saillaravel一起使用

嗨,我刚刚尝试安装带有风帆的 Laravel 8,但遇到了问题

我所做的是首先从 Laravel 自己的页面运行 curl one-liner

curl -s https://laravel.build/sail-test | bash

一旦完成我就按照它说的运行

cd sail-test && ./vendor/bin/sail up

一切都按原样开始,我可以连接到数据库,我可以在 http://localhost 上看到该站点,但是在尝试迁移时出现以下错误:

$ sail artisan migrate:install

   IlluminateDatabaseQueryException 

  SQLSTATE[HY000] [2002] No route to host (SQL: create table `migrations` (`id` int unsigned not null auto_increment primary key, `migration` varchar(255) not null, `batch` int not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
    674?         // If an exception occurs when attempting to run a query, we'll format the error
    675?         // message to include the bindings with SQL, which will make this exception a
    676?         // lot more helpful to the developer instead of just the database's errors.
    677?         catch (Exception $e) {
  ? 678?             throw new QueryException(
    679?                 $query, $this->prepareBindings($bindings), $e
    680?             );
    681?         }
    682? 

      +29 vendor frames 
  30  artisan:37
      IlluminateFoundationConsoleKernel::handle()

我需要更改.env文件中的任何内容还是需要先进行任何其他更改?

回答

首先(此命令将返回您的 mysql 容器 IP 地址):

$ docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_name_or_container_ID>

.env 文件中的第二个:

DB_HOST=<ip_address_returned_from_command_above>

进而:

$ sail artisan migrate

编辑:

只需将数据库容器的名称添加到您的 DB_HOST 环境变量中:

...
DB_HOST=mysql
...

  • You can also use the name of the docker image (found in docker-compose.yml). By default that is `DB_HOST=mysql`
  • I'm getting the same response after trying this

以上是不能将migrate与saillaravel一起使用的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>