我在sql中使用函数“join”创建了视图表。但是当我尝试使用gii生成视图表时,有人说“与Rangkuman相关联的表必须具有主键”,并且我已经使用与Rangkuman相关联的表创建了主键。但仍然像这张照片
这是Rangkuman模型
<?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'),
];
}
}
这是sql代码
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`));
我该怎么办?谢谢