#Laravel Deployment | github actions SQLSTATE[HY000] [2002] error

10 messages · Page 1 of 1 (latest)

hoary sentinel
#

Hi,

I wanted to add actions to my project on github and created the following yml file.

name: Update

on:
  push:
    branches:
      - main

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
      with:
        php-version: '8.1'
    - uses: actions/checkout@v3

    - name: Install dependencies
      run: composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts

    - name: Run database migrations
      env:
        DB_CONNECTION: mysql
        DB_DATABASE: database
        DB_USERNAME: root
        DB_PASSWORD: password
      run: php artisan migrate --force

    - name: Clear cache
      run: php artisan optimize:clear

I couldn't find the problem. Can you help me?

ember glacier
#

Why are you trying to run migrations on a MySQL database in a GitHub Actions workflow run?

#

Any database would be lost when the workflow run finishes.

hoary sentinel
#

I want the following commands to run every time I commit to the Github repo. For this reason, I created a yml file as above, but I think I made a logical mistake.
composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
php artisan migrate --force
php artisan optimize:clear

ember glacier
#

I don’t really think you understand what GitHub Actions are.

#

They’re for running things like tests when you commit.

#

You can also use workflows to deploy your changes, but you’re not deploying in your example above.

#

You’re just trying to migrate a database within the workflow run, that will be deleted once the workflow finishes.