Skip to content

How to create a .yml schema file for foreign key contraints #296

@mtech2008

Description

@mtech2008

Hi,
I have a following sql and I want to write a .yml schema file.

CREATE TABLE Programs (
program_id int(11) NOT NULL AUTO_INCREMENT,
program_name varchar(255) DEFAULT NULL,
program_code varchar(50) DEFAULT NULL,
duration varchar(50) DEFAULT NULL,
department_id int(11) DEFAULT NULL,
PRIMARY KEY (program_id),
UNIQUE KEY program_name (program_name),
UNIQUE KEY program_code (program_code),
KEY department_id (department_id),
CONSTRAINT programs_ibfk_1 FOREIGN KEY (department_id) REFERENCES departments (department_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

How could I do that?

The following creates a table without constraints:

increments: false
table: programs
columns:
program_id:
type: integer
primary: true
autoIncrement: true
program_name:
type: string
length: 255
unique: true
nullable: true
program_code:
type: string
length: 50
unique: true
nullable: true
duration:
type: string
length: 50
nullable: true
department_id:
type: integer
index: true
nullable: true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions