简体   繁体   English

SQLSTATE [23000]:完整性约束违规:1052 where子句中的列'NRP'不明确

[英]SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'NRP' in where clause is ambiguous

when I tried to do search in NRP, there was an error. 当我试图在NRP中搜索时,出现了错误。 It said "SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'NRP' in where clause is ambiguous" here is model's code: 它说“SQLSTATE [23000]:完整性约束违规:1052列'NRP'在where子句中是不明确的”这里是模型的代码:

<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "alumnys2".
 *
 * @property integer $Alumnys2ID
 * @property string $NRP
 * @property string $ProgramStudi
 * @property string $Tanggal_Masuk
 * @property string $Tanggal_Lulus
 *
 * @property AlumniIntegrasi $nRP
 */
class AlumnyS2 extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'alumnys2';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['NRP'], 'required'],
            [['NRP'], 'string', 'max' => 15],
            [['ProgramStudi'], 'string', 'max' => 5],
            [['Tanggal_Masuk', 'Tanggal_Lulus'], 'string', 'max' => 30],
            [['NRP'], 'exist', 'skipOnError' => true, 'targetClass' => AlumniIntegrasi::className(), 'targetAttribute' => ['NRP' => 'NRP']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'Alumnys2ID' => Yii::t('app', 'Alumnys2 ID'),
            'NRP' => Yii::t('app', 'Nrp'),
            'ProgramStudi' => Yii::t('app', 'Program Studi'),
            'Tanggal_Masuk' => Yii::t('app', 'Tanggal  Masuk'),
            'Tanggal_Lulus' => Yii::t('app', 'Tanggal  Lulus'),
            'namaMahasiswaText' => Yii::t('app', 'Nama Mahasiswa'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getalumniIntegrasi()
    {
        return $this->hasOne(alumniIntegrasi::className(), ['NRP' => 'NRP']);
    }

    public function getNamaMahasiswaText()
    {
        $alumniIntegrasi = alumniIntegrasi::findOne(['NRP'=> $this->NRP]);
        if (empty($alumniIntegrasi))
            return '';
        return $alumniIntegrasi->NamaMahasiswa;
    }

}

and here is modelsearch codes: 这是模型搜索代码:

<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\AlumnyS2;
use app\models\AlumniIntegrasi;

/**
 * AlumnyS2Search represents the model behind the search form about `app\models\AlumnyS2`.
 */
class AlumnyS2Search extends AlumnyS2
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['Alumnys2ID'], 'integer'],
            [['NRP', 'namaMahasiswaText', 'ProgramStudi', 'Tanggal_Masuk', 'Tanggal_Lulus'], 'safe'],
        ];
    }

    public $NamaMahasiswa;
    public $namaMahasiswaText;

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = AlumnyS2::find();
        $query->joinWith('alumniIntegrasi');
        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }



        // grid filtering conditions
        $query->andFilterWhere([
            'Alumnys2ID' => $this->Alumnys2ID,
        ]);

        $query->andFilterWhere(['like', 'NRP', $this->NRP])
            ->andFilterWhere(['like', 'alumniIntegrasi.NamaMahasiswa', $this->namaMahasiswaText])
            ->andFilterWhere(['like', 'ProgramStudi', $this->ProgramStudi])
            ->andFilterWhere(['like', 'Tanggal_Masuk', $this->Tanggal_Masuk])
            ->andFilterWhere(['like', 'Tanggal_Lulus', $this->Tanggal_Lulus]);

        return $dataProvider;
    }
}

and here is the index: 这是索引:

<?php

use yii\helpers\Html;
use yii\grid\GridView;
use app\models\AlumniIntegrasi;

/* @var $this yii\web\View */
/* @var $searchModel app\models\AlumnyS2Search */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Alumny S2s');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="alumny-s2-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a(Yii::t('app', 'Create Alumny S2'), ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            //'Alumnys2ID',
            'NRP',
            'namaMahasiswaText',
            'ProgramStudi',
            'Tanggal_Masuk',
            'Tanggal_Lulus',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>

I dont know how to fix that problem. 我不知道如何解决这个问题。 somebody help me please to solve this code. 有人帮我解决这个问题。 thankyou so much 非常感谢

MY PROBLEM IS FIXED I change the query codes to be like this: 我的问题是固定的我将查询代码更改为:

 $query->andFilterWhere(['like', 'alumnys2.NRP', $this->NRP])
            ->andFilterWhere(['like', 'alumniIntegrasi.NamaMahasiswa', $this->namaMahasiswaText])
            ->andFilterWhere(['like', 'alumnys2.ProgramStudi', $this->ProgramStudi])
            ->andFilterWhere(['like', 'alumnys2.Tanggal_Masuk', $this->Tanggal_Masuk])
            ->andFilterWhere(['like', 'alumnys2.Tanggal_Lulus', $this->Tanggal_Lulus]);

By changing Filter query 通过更改筛选查询

 $query->andFilterWhere([
                'tbl_Yourtablename.NRP' => $this->NRP,
                'tbl_Yourtablename.namaMahasiswaText' => $this->namaMahasiswaText,
                'tbl_Yourtablename.ProgramStudi' => $this->ProgramStudi,
                'tbl_Yourtablename.Tanggal_Masuk' => $this->Tanggal_Masuk,
                'tbl_Yourtablename.Tanggal_Lulus' => $this->Tanggal_Lulus

            ]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQLSTATE [23000]:完整性约束违规:1052 where子句中的列&#39;status&#39;不明确 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'status' in where clause is ambiguous Laravel 6 错误:SQLSTATE[23000]:违反完整性约束:1052 where 子句中的列“id_perusahaan”不明确 - Laravel 6 Error : SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id_perusahaan' in where clause is ambiguous SQLSTATE [23000]:违反完整性约束:1052 where 子句中的列“值”不明确 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'value' in where clause is ambiguous Laravel Eloquent SQLSTATE[23000]:违反完整性约束:1052 列...在 where 子句中不明确 - Laravel Eloquent SQLSTATE[23000]: Integrity constraint violation: 1052 Column ... in where clause is ambiguous SQLSTATE [23000]:完整性约束违规:1052 order order中的&#39;created_at&#39;列不明确Laravel 5.5 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 5.5 Yii2 GridView:SQLSTATE[23000]:违反完整性约束:1052 order 子句中的列“id”不明确 - Yii2 GridView: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in order clause is ambiguous SQLSTATE [23000]:完整性约束违规:1052 列“created_at”在 order 子句中不明确 Laravel 8 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 8 完整性约束违规:1052 where子句中的列&#39;id&#39;不明确 - Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous Laravel 完整性约束违规:1052 列 'id' in where 子句不明确 - Laravel Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous PDOException:SQLSTATE [23000]:违反完整性约束:1052 IN / ALL / ANY子查询中的列“ category_id”不明确 - PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'category_id' in IN/ALL/ANY subquery is ambiguous
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM