简体   繁体   中英

Error when trying to run adonis JS migration

Error is displayed when trying to run the migration.

I'm using the migration created by Adonis Auth himself. In which the token table is created.

The error is shown when trying to create this table and mariadb immediately closes.

I'm using mysql2

import BaseSchema from '@ioc:Adonis/Lucid/Schema'

export default class ApiTokens extends BaseSchema {
  protected tableName = 'api_tokens'

  public async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments('id').primary()
      table.integer('user_id').unsigned().references('id').inTable('users').onDelete('CASCADE')
      table.string('name').notNullable()
      table.string('type').notNullable()
      table.string('token', 64).notNullable().unique()

      /**
       * Uses timestampz for PostgreSQL and DATETIME2 for MSSQL
       */
      table.timestamp('expires_at', { useTz: true }).nullable()
      table.timestamp('created_at', { useTz: true }).notNullable()
    })
  }

  public async down() {
    this.schema.dropTable(this.tableName)
  }
}

Erro

node ace migration:run
[ info ]  Upgrading migrations version from "1" to "2"
❯ migrated database/migrations/1663627357202_users
❯ error database/migrations/1663627357216_api_tokens

  Error

 Connection lost: The server closed the connection.


   1  Socket.<anonymous>
     ..../node_modules/mysql2/lib/connection.js:101

I recommend restarting the server node ace serve --watch , before running the migrations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM