是否可以在Laravel Migration中使用sql查询

时间:2018-07-25 03:19:02

标签: php laravel-5

我有一个如下的创建表查询

> CREATE TABLE ep_student (
>     student_id BIGSERIAL  NOT NULL,
>     stud_name CHARACTER(150)  NOT NULL,
>     no_kp CHARACTER(14)  NOT NULL,
>     dob DATE,
>     birth_place CHARACTER(100),
>     pob_desc CHARACTER(100),
>     dt_enroll DATE,
>     enroll_darjah CHARACTER(20),
>     religion_id CHARACTER(10),
>     ethnic_id CHARACTER(10),
>     citizenship_id CHARACTER(10),
>     warga_desc CHARACTER(100),
>     gender_id CHARACTER(10),
>     autisma_flag CHARACTER(10),
>     lelah_flag CHARACTER(10),
>     heart_flag CHARACTER(10),
>     skin_flag CHARACTER(10),
>     allergy_flag CHARACTER(10),
>     disability_flag CHARACTER(10),
>     disease_desc CHARACTER(100),
>     disability_desc CHARACTER(100),
>     dt_leftschool DATE,
>     reason_leftschool CHARACTER(100),
>     school_id BIGINT  NOT NULL,
>     birth_cert CHARACTER(20),
>     CONSTRAINT PK_ep_student PRIMARY KEY (student_id, no_kp, school_id)

我可以在Laravel Migration文件中使用DB :: create并将方案粘贴到其中吗?

1 个答案:

答案 0 :(得分:0)

要执行查询以进行迁移,可以使用DB类的statement()方法。

DB::statement("
    CREATE TABLE `your_table` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `status` tinyint(3) unsigned DEFAULT NULL,
        PRIMARY KEY (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
");

祝你好运