What is wrong in this Adonisjs relationship

Asked

Viewed 990 times

0

I’m having the following mistake when I give Adonis Migration:run :

    { error: relation "polo" does not exist
    at Connection.parseE (C:\ckinfo\node_modules\pg\lib\connection.js:604:11)
    at Connection.parseMessage (C:\ckinfo\node_modules\pg\lib\connection.js:401:19)
    at Socket.<anonymous> (C:\ckinfo\node_modules\pg\lib\connection.js:121:22)
    at Socket.emit (events.js:198:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at Socket.Readable.push (_stream_readable.js:224:10)
    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
From previous event:
    at Client_PG._query (C:\ckinfo\node_modules\knex\lib\dialects\postgres\index.js:260:12)
    at Client_PG.query (C:\ckinfo\node_modules\knex\lib\client.js:202:17)
    at C:\ckinfo\node_modules\knex\lib\transaction.js:272:21
From previous event:
    at Client_PG.trxClient.query (C:\ckinfo\node_modules\knex\lib\transaction.js:269:34)
    at Runner.<anonymous> (C:\ckinfo\node_modules\knex\lib\runner.js:146:36)
From previous event:
    at Runner.<anonymous> (C:\ckinfo\node_modules\knex\lib\runner.js:213:19)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
From previous event:
    at Runner.queryArray (C:\ckinfo\node_modules\knex\lib\runner.js:212:106)
    at C:\ckinfo\node_modules\knex\lib\runner.js:46:23
From previous event:
    at Runner.run (C:\ckinfo\node_modules\knex\lib\runner.js:34:31)
    at SchemaBuilder.Target.then (C:\ckinfo\node_modules\knex\lib\interface.js:20:43)
  name: 'error',
  length: 163,
  severity: 'ERROR',
  code: '42P01',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file:
   'd:\\pginstaller.auto\\postgres.windows-x64\\src\\backend\\catalog\\namespace.c',
  line: '426',
  routine: 'RangeVarGetRelidExtended' }

Polo.js 'use Strict'

/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
const Model = use('Model')

class Polo extends Model {

    //
    departamentos () {
        return this.hasMany('App/Models/Departamento')
    }

    endereco () {
        return this.hasOne('App/Models/Endereco')
    }
}

module.exports = Polo

MIGRATION FROM THE POLE

'use strict'

/** @type {import('@adonisjs/lucid/src/Schema')} */
const Schema = use('Schema')

class PoloSchema extends Schema {
  up () {
    this.create('polos', (table) => {
      table.increments()
      table.string('nome')
      table.string('endereco')
      table.timestamps()
    })
  }

  down () {
    this.drop('polos')
  }
}

module.exports = PoloSchema

Departamento.js

'use strict'

/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
const Model = use('Model')

class Departamento extends Model {

    //

    telefones() {
        return this.hasMany('App/Models/Telefone')
    }

    polo() {
        return this.belongsTo('App/Models/Polo')
    }
}

module.exports = Departamento

MIGRATION OF THE DEPARTMENT

'use strict'

/** @type {import('@adonisjs/lucid/src/Schema')} */
const Schema = use('Schema')

class DepartamentoSchema extends Schema {
  up () {
    this.create('departamentos', (table) => {
      table.increments()
      table.string('nome')
      table.string('gerente')
      table.integer('id_polo')
      .unsigned()
      .references('id')
      .inTable('polo')
      .onUpdate('CASCADE')
      .onDelete('CASCADE')
      table.timestamps()
    })
  }

  down () {
    this.drop('departamentos')
  }
}

module.exports = DepartamentoSchema

Endereco.js

'

use strict'

/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
const Model = use('Model')

class Endereco extends Model {



    polo () {
        return this.belongsTo('App/Models/Polo')
    }
}

module.exports = Endereco

MIGRATION OF THE ADDRESS

'use strict'

/** @type {import('@adonisjs/lucid/src/Schema')} */
const Schema = use('Schema')

class EnderecoSchema extends Schema {
  up () {
    this.create('enderecos', (table) => {
      table.increments()

      table
      .integer('polo_id')
      .unsigned()
      .references('id')
      .inTable('polo')
      .onUpdate('CASCADE')
      .onDelete('CASCADE')

      table.string('gix')
      table.string('rb')
      table.string('vm')
      table.timestamps()
    })
  }

  down () {
    this.drop('enderecos')
  }
}

module.exports = EnderecoSchema
  • the name you gave was POLES, but you called it in another file as POLO, there appears the error that it does not exist

  • Hello, thank you for answering. I just corrected and now says that POLES does not exist

1 answer

0

The name you gave to table was poles, but in the department Migrations and address you put in .inTable('polo') as polo and not poles which is the name of the reference table.

Change to .inTable('polos') and check if the error still occurs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.