Why can't I create CRUD with GII in Yii2

时光总嘲笑我的痴心妄想 提交于 2020-01-06 18:37:10

问题


I have made the view table with function "join" in sql. but when I try to generate the view table with gii, it was said that "Table associated with Rangkuman must have primary key", and I have made primary key with table that associated with Rangkuman. But still be like this picture

Here is Rangkuman model

<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "rangkuman".
 *
 * @property string $Fakultas
 * @property string $Departemen
 * @property string $KodeMayor
 * @property string $NIM
 * @property integer $TahunMasuk
 * @property integer $JenisKelamin
 * @property integer $StatusAkademik
 * @property string $Usia
 */
class Rangkuman extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'rangkuman';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['Fakultas', 'Departemen', 'NIM', 'JenisKelamin'], 'required'],
            [['TahunMasuk', 'JenisKelamin', 'StatusAkademik', 'Usia'], 'integer'],
            [['Fakultas', 'Departemen'], 'string', 'max' => 5],
            [['KodeMayor'], 'string', 'max' => 10],
            [['NIM'], 'string', 'max' => 11],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'Fakultas' => Yii::t('app', 'Fakultas'),
            'Departemen' => Yii::t('app', 'Departemen'),
            'KodeMayor' => Yii::t('app', 'Kode Mayor'),
            'NIM' => Yii::t('app', 'Nim'),
            'TahunMasuk' => Yii::t('app', 'Tahun Masuk'),
            'JenisKelamin' => Yii::t('app', 'Jenis Kelamin'),
            'StatusAkademik' => Yii::t('app', 'Status Akademik'),
            'Usia' => Yii::t('app', 'Usia'),
        ];
    }
}

and here is the sql code

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `rangkuman` AS select `dbintegrasi`.`ipbmst_fakultas`.`Kode` AS `Fakultas`,
`dbintegrasi`.`ipbmst_departemen`.`Kode` AS `Departemen`,
`dbintegrasi`.`akdmst_mayor`.`Kode` AS `KodeMayor`,
`dbintegrasi`.`akdmst_mahasiswadoktor`.`NIM` AS `NIM`,
`dbintegrasi`.`akdmst_mahasiswadoktor`.`TahunMasuk` AS `TahunMasuk`,
`dbintegrasi`.`ipbmst_orang`.`JenisKelaminID` AS `JenisKelamin`,
`dbintegrasi`.`akdmst_mahasiswadoktor`.`StatusAkademikID` AS `StatusAkademik`,
timestampdiff(YEAR,`dbintegrasi`.`ipbmst_orang`.`TanggalLahir`,now()) AS `Usia`  
from (((((`dbintegrasi`.`akdmst_mahasiswadoktor` join `dbintegrasi`.`akdmst_mayor`
on((`dbintegrasi`.`akdmst_mahasiswadoktor`.`MayorID` = `dbintegrasi`.`akdmst_mayor`.`ID`))) 
join `dbintegrasi`.`ipbmst_departemen` on((`dbintegrasi`.`akdmst_mayor`.`DepartemenID` = `dbintegrasi`.`ipbmst_departemen`.`ID`))) 
join `dbintegrasi`.`ipbmst_fakultas` on((`dbintegrasi`.`ipbmst_departemen`.`FakultasID` = `dbintegrasi`.`ipbmst_fakultas`.`ID`))) 
join `dbintegrasi`.`ipbmst_orang` on((`dbintegrasi`.`akdmst_mahasiswadoktor`.`NIM` = `dbintegrasi`.`ipbmst_orang`.`NIMS3Key`))) 
join `dbintegrasi`.`akdref_statusakademik` on((`dbintegrasi`.`akdmst_mahasiswadoktor`.`StatusAkademikID` = `dbintegrasi`.`akdref_statusakademik`.`ID`)))
join `dbintegrasi`.`ipbref_jeniskelamin` on((`dbintegrasi`.`ipbmst_orang`.`JenisKelaminID` = `dbintegrasi`.`ipbref_jeniskelamin`.`ID`));

What should I do? Thank you

来源:https://stackoverflow.com/questions/42504811/why-cant-i-create-crud-with-gii-in-yii2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!