Class AlterTableBuilder

This builder can be used to create a alter table query.

Hierarchy

  • AlterTableBuilder

Implements

Constructors

Methods

  • See addForeignKeyConstraint

    Unlike addForeignKeyConstraint this method returns the constraint builder and doesn't take a callback as the last argument. This is because you can only add one column per ALTER TABLE query.

    Parameters

    • constraintName: string
    • columns: string[]
    • targetTable: string
    • targetColumns: string[]

    Returns AlterTableAddForeignKeyConstraintBuilder

  • This can be used to add index to table.

    Examples

    db.schema.alterTable('person')
    .addIndex('person_email_index')
    .column('email')
    .unique()
    .execute()

    The generated SQL (MySQL):

    alter table `person` add unique index `person_email_index` (`email`)
    

    Parameters

    • indexName: string

    Returns AlterTableAddIndexBuilder

  • This can be used to drop index from table.

    Examples

    db.schema.alterTable('person')
    .dropIndex('person_email_index')
    .execute()

    The generated SQL (MySQL):

    alter table `person` drop index `test_first_name_index`
    

    Parameters

    • indexName: string

    Returns AlterTableExecutor

Generated using TypeDoc