Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

iamkarsoft's avatar

How to run migrations or force them in github workflow

How do you run force migrations with github workflows?

name: CI CD Laravel
on:
  push:
    branches:
    - production
jobs:
  laravel-continuous-deployment:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: Install Dependencies (PHP vendors)
      run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
    - name: Run Migration
      run: |
        php artisan migrate --force

everything runs well until it reaches the migration part. then it fails.

0 likes
12 replies
iamkarsoft's avatar
Run php artisan migrate --force

   Illuminate\Database\QueryException 

  SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = forge and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
    667▕         // If an exception occurs when attempting to run a query, we'll format the error
    668▕         // message to include the bindings with SQL, which will make this exception a
    669▕         // lot more helpful to the developer instead of just the database's errors.
    670▕         catch (Exception $e) {
  ➜ 671▕             throw new QueryException(
    672▕                 $query, $this->prepareBindings($bindings), $e
    673▕             );
    674▕         }
    675▕

      +39 vendor frames 
  40  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()
Error: Process completed with exit code 1.

This is the latest error i'm getting

Sinnbeck's avatar

Are you sure your env is correctly set up? It seems to not be able to connect

iamkarsoft's avatar

is there something I'm missing? when i run PHP artisan migrate after ssh into my server. it runs with no issues. i wonder that I'm missing. every connection in my env works fine.

Sinnbeck's avatar

But how is github supposed to log into your forge database? And why should it migrate your database? I assume your tests does this themselves?

iamkarsoft's avatar

interesting. I'm not even using forge. my app is hosted on D.O, and i use buddy as one of the CD pipelines. then i guess the problem is that GitHub isn't able to access my database right? any tips or ways i can make GitHub connect to the database?

Sinnbeck's avatar

First I need to understand, why it should connect to your database? I assume you just need to run tests ? It should have its own database to test on :)

iamkarsoft's avatar

I do not run or write tests. I'm not an expert. but when i create new tables or edit tables on the dev machine? i want it to run new migrations when the code is pushed to the production environment.

iamkarsoft's avatar
iamkarsoft
OP
Best Answer
Level 21
 steps:
      - name: Checkout code
        uses: actions/checkout@v1

      - name: Install dependencies
        run: composer install --no-interaction --no-suggest --ignore-platform-reqs

Please or to participate in this conversation.