# Can not run migrate in CircleCI with knex migration

**URL:** <https://discuss.circleci.com/t/can-not-run-migrate-in-circleci-with-knex-migration/30549>\
**Category:** Databases\
**Tags:** postgresql, nodejs, circle-yml\
**Created:** [May 24, 2019, 8:28am UTC](https://discuss.circleci.com/t/can-not-run-migrate-in-circleci-with-knex-migration/30549 "2019-05-24T08:28:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tienvv1234](https://avatars.discourse-cdn.com/v4/letter/t/df788c/32.png) [@tienvv1234](https://discuss.circleci.com/u/tienvv1234)\
**Post date:** [May 24, 2019, 8:28am UTC](https://discuss.circleci.com/t/can-not-run-migrate-in-circleci-with-knex-migration/30549/1 "2019-05-24T08:28:53Z")

</div>

I want to Create a database for integration test by Circle CI and here is the .config.yml Circle CI config

```
    version: 2 # use CircleCI 2.0
jobs: # a collection of steps
  build: # runs not using Workflows must have a `build` job as entry point
    docker: # run the steps with Docker
      - image: circleci/node:10.15.0
        environment:
            POSTGRES_HOST: 'postgresql://postgres:password@localhost:5432/testdb'
            POSTGRES_USER: postgres
            POSTGRES_PASSWORD: password
            POSTGRES_DB: testdb
      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      - image: circleci/redis:latest
      - image: mdillon/postgis
        environment:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: password
          POSTGRES_DB: testdb

    working_directory: ~/nodejs_typescript

    steps: # a collection of executable commands
      - checkout

      - run:
          name: update-npm
          command: 'sudo npm install -g npm@latest'

      # Download and cache dependencies
      - restore_cache: # special step to restore the dependency cache
          # Read about caching dependencies: https://circleci.com/docs/2.0/caching/
          key: dependency-cache-{{ checksum "package.json" }}

      - run:
          name: install-npm-wee
          command: npm install

      - save_cache:
          name: Save-Cache
          paths:
            - './node_modules'
          key: dependency-cache-{{ checksum "package.json"}}

      - run:
          name: install-global-knex
          command: sudo npm install -g knex

      - run: sudo apt-get update
      - run: sudo apt-get install postgresql-client-9.6 -y

      - run: 
         name: Create database
         command: psql -U postgres -h localhost -p 5432 -tc "SELECT 1 FROM pg_database WHERE datname = 'testdb'" | grep -q 1 || psql -U postgres -h localhost -p 5432 -c "CREATE DATABASE testdb"

      - run:
          name: Knex Migrations
          command: knex migrate:latest --knexfile src/knexfile.ts --env test
          environment:
            NODE_ENV: test
            
      - run:
          name: Knex seeds
          command: knex seed:run --knexfile src/knexfile.ts --env test
          environment:
            NODE_ENV: test

      - run: # run tests
          name: test
          command: npm run test
          environment:
            NODE_ENV: test

```

but the build is broken when running the command `knex migrate:latest --knexfile src/knexfile.ts --env test` and here is the error

Using environment: test  
Error: getaddrinfo ENOTFOUND postgresql://postgres:password@localhost:5432/testdb postgresql://postgres:password@localhost:5432/testdb:5432  
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)  
Exited with code 1

I don’t know why I cannot run the migration from knex, can anyone help me, please
