Yii seems to neglect AUTO_INREMENT for PrimaryKey

[size="2"]Hi guys,

primary keys in all tables(about 120) of our database are set to AUTO_INCREMENT.[/size]

[size="2"]

I noticed,that yii2 seems to neglect this guideline. [/size]

[size="2"]If I use to create a new record (without filling in PrimaryKey in view, of course) new record will have an id, which is [color="#0C0C0C"][font="Arial, sans-serif"]completely [/font][/color][color="#181818"][font="Arial, sans-serif"]wit[/font][/color][color="#242424"][font="Arial, sans-serif"]hout [/font][/color][color="#303030"][font="Arial, sans-serif"]fo[/font][/color][color="#3C3C3C"][font="Arial, sans-serif"]undati[/font][/color][color="#303030"][font="Arial, sans-serif"]on[/font][/color][color="#242424"][font="Arial, sans-serif"] [/font][/color][color="#3C3C3C"][font="Arial, sans-serif"][color="#242424"]in fact[/color].[/font][/color][/size]

[size="2"][font="Arial, sans-serif"] [/font][color="#3C3C3C"][font="Arial, sans-serif"]For instance, I have two records in table, which are created using phpmyadmin by id=1/id=2.[/font][/color]

[color="#3C3C3C"][font="Arial, sans-serif"]New record,created using yii will have id 4191.[/font][/color]

[color="#3C3C3C"][font="Arial, sans-serif"]Furthermore, I sometimes get error :


Duplicate entry for Primary Key

[/font][/color]

[color="#3C3C3C"][font="Arial, sans-serif"] [/font][/color]

[color="#3C3C3C"][font="Arial, sans-serif"]Any ideas,how to fix this probelm?[/font][/color][/size]

[color="#3C3C3C"][font="Arial, sans-serif"] [/font][/color]

its very likely you are inserting/overriding the primary key with your data. can you paste your code here

I neither are inserting nor overriding primary key with any data. I laready told U, that primary key will be set AUTO_INCREMENT, so it won’t be written in/by formular.

Here is formular




.

.

.

 	<?= $form->field($model, 'id', ['template' => '{input}'])->textInput(['style' => 'display:none']); ?>

.

.

.



Here is controller,which is responsible for writing id [color="#0C0C0C"][size="2"][font="Arial, sans-serif"]completely [/font][/size][/color][color="#181818"][size="2"][font="Arial, sans-serif"]wit[/font][/size][/color][color="#242424"][size="2"][font="Arial, sans-serif"]hout [/font][/size][/color][color="#303030"][size="2"][font="Arial, sans-serif"]fo[/font][/size][/color][color="#3C3C3C"][size="2"][font="Arial, sans-serif"]undati[/font][/size][/color][color="#303030"][size="2"][font="Arial, sans-serif"]on[/font][/size][/color][color="#242424"][size="2"][font="Arial, sans-serif"] [/font][/size][/color][color="#3C3C3C"][size="2"][font="Arial, sans-serif"][color="#242424"]in fact[/color].[/font][/size][/color]





    public function actionCreate() {

        //try {


        $model = new Bewerber(['scenario' => Bewerber::SCENARIO_CREATE]);

        $behavior = new \common\wsl_components\Wsl_Blameable_Behavior();

        $angelegt_von = $behavior->get_User_Person_Id();

        if (!$model) {

            throw new NotFoundHttpException("Bitte überprüfen Sie die Validität der Tabellen bewerber bzw. person");

        }

        $model->angelegt_von = $angelegt_von;


        if ($model->load(Yii::$app->request->post())) {

            $isValid = $model->validate();

            if ($isValid) {

                $model->avatar = UploadedFile::getInstances($model, 'avatar');

                $model->upload();

                $model->save();

                return $this->redirect(['view', 'id' => $model->id]);

            } else {

                $error_bewerber = $model->getErrors();              

                foreach ($error_bewerber as $values) {

                    foreach ($values as $ausgabe) {

                        echo"<p>" . $ausgabe . "</p>";

                    }

                }

                echo Growl::widget([

                    'type' => Growl::TYPE_DANGER,

                    'title' => 'Oh snap!',

                    'icon' => 'glyphicon glyphicon-remove-sign',

                    'body' => 'Aus unbekannten Gründen konnten die Tabellen nicht validiert werden<br>Bitte informieren Sie den Hersteller gemäß obiger Angaben!',

                    'showSeparator' => true,

                    'delay' => 2000,

                    'pluginOptions' => [

                        'showProgressbar' => true,

                        'placement' => [

                            'from' => 'top',

                            'align' => 'center',

                        ]

                    ]

                ]);

                return $this->render('create', [

                            'model' => $model,

                ]);

            }

        } else {

            return $this->render('create', [

                        'model' => $model,

            ]);

        }

        /* } catch (\Exception $error) {

          $go_back = "bewerber";

          \common\wsl_components\error_handling::error($error, $go_back);

          } */

    }



Do not include ‘id’ field in the form.

Why not?

As U can see, style was set to


display:none

[size=“2”]So, it won’t be shown up anyway. Of course, this code seems to be superflous, but however, in future I maybe want to fill in id manually. I couldn’t, if I exclude this field.[/size]

Sure, if ur hint helped, I’d remove it!

I just don’t understand, why including a non-visible field could interfere framework doing its job correctly

You don’t want to do that!

Or, if you do, you do need to turn off auto increment.

You can’t have both - and why would you?

[Edit]

The id field is something that goes on behind the scenes, and is none of your concern, IMO.

Okay. In actual fact, I don’t want to fill in id manually. U wrote, that id filed is something,that goes on behind the scenes. So, I absolutely don’t understand, why

[list=1][]framework is creating id’s which are [color="#0C0C0C"][size=“2”][font=“Arial, sans-serif”]completely [/font][/size][/color][color="#181818"][size=“2”][font=“Arial, sans-serif”]wit[/font][/size][/color][color="#242424"][size=“2”][font=“Arial, sans-serif”]hout [/font][/size][/color][color="#303030"][size=“2”][font=“Arial, sans-serif”]fo[/font][/size][/color][color="#3C3C3C"][size=“2”][font=“Arial, sans-serif”]undati[/font][/size][/color][color="#303030"][size=“2”][font=“Arial, sans-serif”]on[/font][/size][/color][color="#242424"][size=“2”][font=“Arial, sans-serif”] [/font][/size][/color][color="#3C3C3C"][size=“2”][font=“Arial, sans-serif”][color="#242424"]in fact[/color][/font][/size][/color][][color="#3C3C3C"][size=“2”][font=“Arial, sans-serif”][color="#242424"]I sometimes got error :"[/color][/font][/size][/color]Duplicate[size=“2”] entry [/size][color="#000088"][size=“2”]for[/size][/color] [color="#660066"][size=“2”]Primary[/size][/color] [color="#660066"][size=“2”]Key"[/size][/color][/list]

[font=“Arial, sans-serif”][color="#242424"][size=“2”]Is the answer to this question really, 'cause I implemented an id field in formular,which was hidden.[/size][/color][/font] I can’t belive that…

Do you know how the Sun just shines, and it is nothing you need to mess with? Same here, just listen to replies, they are correct.

That’s because both you and your database are racing against the clock to create a primary key id.

“Duplicate entry” error means that you lost that race. :)

It never happens without some errors in your code. This is 100% sure. Stop questioning the framework and start to debug your code.

You may not be aware of if, but the fact is that you are setting the PK manually somewhere in your code before inserting a record. The error(s) may not be in the controller, but in the view script or in the model code.

And consider using vanilla yii without any extensions. The extensions might not be very helpful when you are new to the framework core. I hope removing them for the moment will greatly ease your development effort.

Yes, and try and use Gii to generate CRUD for your application.

Even if you are not going to use it, it will show you how fully working and idiomatic Yii 2 code looks like.

indeed as it turns you were overriding the primary key with the id field in your form. heck you must listen when you looking for help, it does not cost you anything try out suggested solution or you can bang your head against it yourself.


// this is where the problem was

 <?= $form->field($model, 'id', ['template' => '{input}'])->textInput(['style' => 'display:none']); ?>

I did use Gii in order to generate _form.php (formular),as I generate scripts using Gii, wherever it is possible(creating models,for instance)

In Gii, I used to set id to be hidden. So, this code has been generated by Gii…

I removed this code now.,in order to try out suggested solution by alrazi. So, I hope, things will gonna get all right,by now!

P.S.: Thx for all giving me feedback.Thx more particulary for azari && softdark. I recognize ur efforts giving u reputation point

Oh, I will listen to replies. But I also try to understand them…

Doesn’t help!

After having removed this code,next id being created of yii will be 84686, although it sholud be 8. 7 records are in table, so the new one should be 8 sholudn’t it?

Second record, I am creating will throw out error like this





[b]Integrity constraint violation – [url="http://www.yiiframework.com/doc-2.0/yii-db-integrityexception.html"]yii\db\IntegrityException[/url][/b]

                

[b]SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '3' for key 'PRIMARY'

The SQL being executed was: INSERT INTO `person` (`angelegt_von`, `angelegt_am`, `aktualisiert_am`, `id_person_art`, `id_person_mitarbeiter`, `id_personentyp_dominant`, `id_personentyp_peripher`, `id_personentyp_defizit`, `id_familienstand`, `id_anrede`, `id_titel`, `vorname`, `nachname`, `anrede_persoenlich`, `anrede_duzen`, `geburtsdatum`, `geburtsort`, `geburtsland`, `bemerkung_intern`, `schwerbehindert`, `einschraenkungen`, `aktiv`, `zuletzt_deaktiviert_am`, `aktualisiert_von`, `id`) VALUES (2, NOW(), NOW(), 2, NULL, NULL, NULL, NULL, 4, 1, NULL, 'llll', 'oooo', 1, 1, NULL, '', '', '', 1, '', 1, NULL, 2, 3)[/b]




This is formular. In formular,id will nowhere be defined. Nevertheless, I will get error above. If I repeat creating,pushing repeat symbol of browser, record will be created. What the hell am I doing wrong?





                                    <?=

                                    $form->field($model_person, 'angelegt_am')->widget(\kartik\datecontrol\DateControl::classname(), [

                                        'type' => \kartik\datecontrol\DateControl::FORMAT_DATETIME,

                                        'disabled' => true,

                                    ]);

                                    ?>


                                    <?=

                                    $form->field($model_person, 'aktualisiert_am')->widget(\kartik\datecontrol\DateControl::classname(), [

                                        'type' => \kartik\datecontrol\DateControl::FORMAT_DATETIME,

                                        'disabled' => true,

                                    ]);

                                    ?>


                                    <?=

                                    $form->field($model_person, 'id_person_art')->widget(\kartik\widgets\Select2::classname(), [

                                        'data' => \yii\helpers\ArrayHelper::map(common\modules\lookup\models\base\LPersonArt::find()->orderBy('id')->asArray()->all(), 'id', 'person_art'),

                                        'options' => ['placeholder' => Yii::t('app', 'Bitte eine der drei Hauptpersonengruppen auswählen')],

                                        'pluginOptions' => [

                                            'allowClear' => true

                                        ],

                                    ]);

                                    ?>


                                    <?=

                                    $form->field($model_person, 'id_person_mitarbeiter')->widget(\kartik\widgets\Select2::classname(), [

                                        'data' => \yii\helpers\ArrayHelper::map(Person::find()->orderBy('id')->asArray()->all(), 'id', 'nachname'),

                                        'options' => ['placeholder' => Yii::t('app', 'Bitte die reflexive Personengruppe auswählen')],

                                        'pluginOptions' => [

                                            'allowClear' => true

                                        ],

                                    ]);

                                    ?>


                                    <?=

                                    $form->field($model_person, 'id_personentyp_dominant')->widget(\kartik\widgets\Select2::classname(), [

                                        'data' => \yii\helpers\ArrayHelper::map(\common\modules\lookup\models\LPersonentyp::find()->orderBy('id')->asArray()->all(), 'id', 'typ_name'),

                                        'options' => ['placeholder' => Yii::t('app', 'Bitte wählen Sie eine Chakterisierung aus')],

                                        'pluginOptions' => [

                                            'allowClear' => true

                                        ],

                                    ]);

                                    ?>


                                    <?=

                                    $form->field($model_person, 'id_personentyp_peripher')->widget(\kartik\widgets\Select2::classname(), [

                                        'data' => \yii\helpers\ArrayHelper::map(\common\modules\lookup\models\LPersonentyp::find()->orderBy('id')->asArray()->all(), 'id', 'typ_allgemein_eigenschaft_1'),

                                        'options' => ['placeholder' => Yii::t('app', 'Bitte wählen Sie eine Chakterisierung aus')],

                                        'pluginOptions' => [

                                            'allowClear' => true

                                        ],

                                    ]);

                                    ?>


                                    <?=

                                    $form->field($model_person, 'id_personentyp_defizit')->widget(\kartik\widgets\Select2::classname(), [

                                        'data' => \yii\helpers\ArrayHelper::map(\common\modules\lookup\models\LPersonentyp::find()->orderBy('id')->asArray()->all(), 'id', 'typ_allgemein_eigenschaft_2'),

                                        'options' => ['placeholder' => Yii::t('app', 'Bitte wählen Sie eine Chakterisierung aus')],

                                        'pluginOptions' => [

                                            'allowClear' => true

                                        ],

                                    ]);

                                    ?>


                                    <?=

                                    $form->field($model_person, 'id_familienstand')->widget(\kartik\widgets\Select2::classname(), [

                                        'data' => \yii\helpers\ArrayHelper::map(common\modules\lookup\models\LFamilienstand::find()->orderBy('id')->asArray()->all(), 'id', 'familienstand'),

                                        'options' => ['placeholder' => Yii::t('app', 'Bitte wählen Sie den Familienstand aus')],

                                        'pluginOptions' => [

                                            'allowClear' => true

                                        ],

                                    ]);

                                    ?>


                                    <?=

                                    $form->field($model_person, 'id_anrede')->widget(\kartik\widgets\Select2::classname(), [

                                        'data' => \yii\helpers\ArrayHelper::map(\common\modules\lookup\models\LAnrede::find()->orderBy('id')->asArray()->all(), 'id', 'anrede'),

                                        'options' => ['placeholder' => Yii::t('app', 'Bitte wählen Sie die Anrede')],

                                        'pluginOptions' => [

                                            'allowClear' => true

                                        ],

                                    ]);

                                    ?>


                                    <?=

                                    $form->field($model_person, 'id_titel')->widget(\kartik\widgets\Select2::classname(), [

                                        'data' => \yii\helpers\ArrayHelper::map(common\modules\lookup\models\base\LTitel::find()->orderBy('id')->asArray()->all(), 'id', 'Titel'),

                                        'options' => ['placeholder' => Yii::t('app', 'Bitte wählen Sie,sofern vorhanden, einen akademischen Grad aus')],

                                        'pluginOptions' => [

                                            'allowClear' => true

                                        ],

                                    ]);

                                    ?>


                                    <?=

                                    $form->field($model_person, 'vorname')->widget(\jlorente\remainingcharacters\RemainingCharacters::classname(), [

                                        'type' => \jlorente\remainingcharacters\RemainingCharacters::INPUT_TEXTAREA,

                                        'text' => Yii::t('app', '{n} characters remaining'),

                                        'label' => [

                                            'tag' => 'p',

                                            'id' => 'my-counter',

                                            'class' => 'counter',

                                            'invalidClass' => 'error'

                                        ],

                                        'options' => [

                                            'rows' => '3',

                                            'class' => 'col-md-12',

                                            'maxlength' => 255,

                                            'placeholder' => Yii::t('app', 'Bitte füllen Sie das Formular aus')

                                        ]

                                    ])

                                    ?>


                                    <?=

                                    $form->field($model_person, 'nachname')->widget(\jlorente\remainingcharacters\RemainingCharacters::classname(), [

                                        'type' => \jlorente\remainingcharacters\RemainingCharacters::INPUT_TEXTAREA,

                                        'text' => Yii::t('app', '{n} characters remaining'),

                                        'label' => [

                                            'tag' => 'p',

                                            'id' => 'my-counter',

                                            'class' => 'counter',

                                            'invalidClass' => 'error'

                                        ],

                                        'options' => [

                                            'rows' => '3',

                                            'class' => 'col-md-12',

                                            'maxlength' => 255,

                                            'placeholder' => Yii::t('app', 'Bitte füllen Sie das Formular aus')

                                        ]

                                    ])

                                    ?>


                                    <?=

                                    $form->field($model_person, 'anrede_persoenlich')->widget(\kartik\checkbox\CheckboxX::classname(), [

                                        'autoLabel' => true

                                    ])->label(false);

                                    ?>


                                    <?=

                                    $form->field($model_person, 'anrede_duzen')->widget(\kartik\checkbox\CheckboxX::classname(), [

                                        'autoLabel' => true

                                    ])->label(false);

                                    ?>


                                    <?=

                                    $form->field($model_person, 'geburtsdatum')->widget(\kartik\date\DatePicker::classname(), [

                                        'options' => ['placeholder' => 'Bitte definieren Sie ein Datum'],

                                        'pluginOptions' => [

                                            'format' => 'yyyy-mm-dd',

                                            'todayHighlight' => true,

                                            'calendarWeeks' => true,

                                            'autoclose' => true

                                        ]

                                    ])->label();

                                    ?>


                                    <?=

                                    $form->field($model_person, 'geburtsort')->widget(\jlorente\remainingcharacters\RemainingCharacters::classname(), [

                                        'type' => \jlorente\remainingcharacters\RemainingCharacters::INPUT_TEXTAREA,

                                        'text' => Yii::t('app', '{n} characters remaining'),

                                        'label' => [

                                            'tag' => 'p',

                                            'id' => 'my-counter',

                                            'class' => 'counter',

                                            'invalidClass' => 'error'

                                        ],

                                        'options' => [

                                            'rows' => '3',

                                            'class' => 'col-md-12',

                                            'maxlength' => 255,

                                            'placeholder' => Yii::t('app', 'Bitte füllen Sie das Formular aus')

                                        ]

                                    ])

                                    ?>


                                    <?=

                                    $form->field($model_person, 'geburtsland')->widget(\jlorente\remainingcharacters\RemainingCharacters::classname(), [

                                        'type' => \jlorente\remainingcharacters\RemainingCharacters::INPUT_TEXTAREA,

                                        'text' => Yii::t('app', '{n} characters remaining'),

                                        'label' => [

                                            'tag' => 'p',

                                            'id' => 'my-counter',

                                            'class' => 'counter',

                                            'invalidClass' => 'error'

                                        ],

                                        'options' => [

                                            'rows' => '3',

                                            'class' => 'col-md-12',

                                            'maxlength' => 255,

                                            'placeholder' => Yii::t('app', 'Bitte füllen Sie das Formular aus')

                                        ]

                                    ])

                                    ?>


                                    <?=

                                    $form->field($model_person, 'bemerkung_intern')->widget(\jlorente\remainingcharacters\RemainingCharacters::classname(), [

                                        'type' => \jlorente\remainingcharacters\RemainingCharacters::INPUT_TEXTAREA,

                                        'text' => Yii::t('app', '{n} characters remaining'),

                                        'label' => [

                                            'tag' => 'p',

                                            'id' => 'my-counter',

                                            'class' => 'counter',

                                            'invalidClass' => 'error'

                                        ],

                                        'options' => [

                                            'rows' => '3',

                                            'class' => 'col-md-12',

                                            'maxlength' => 255,

                                            'placeholder' => Yii::t('app', 'Bitte füllen Sie das Formular aus')

                                        ]

                                    ])

                                    ?>


                                    <?=

                                    $form->field($model_person, 'schwerbehindert')->widget(\kartik\checkbox\CheckboxX::classname(), [

                                        'autoLabel' => true

                                    ])->label(false);

                                    ?>


                                    <?=

                                    $form->field($model_person, 'einschraenkungen')->widget(\jlorente\remainingcharacters\RemainingCharacters::classname(), [

                                        'type' => \jlorente\remainingcharacters\RemainingCharacters::INPUT_TEXTAREA,

                                        'text' => Yii::t('app', '{n} characters remaining'),

                                        'label' => [

                                            'tag' => 'p',

                                            'id' => 'my-counter',

                                            'class' => 'counter',

                                            'invalidClass' => 'error'

                                        ],

                                        'options' => [

                                            'rows' => '3',

                                            'class' => 'col-md-12',

                                            'maxlength' => 255,

                                            'placeholder' => Yii::t('app', 'Bitte füllen Sie das Formular aus')

                                        ]

                                    ])

                                    ?>


                                    <?=

                                    $form->field($model_person, 'aktiv')->widget(\kartik\checkbox\CheckboxX::classname(), [

                                        'autoLabel' => true

                                    ])->label(false);

                                    ?>


                                    <?=

                                    $form->field($model_person, 'zuletzt_deaktiviert_am')->widget(\kartik\datetime\DateTimePicker::classname(), [

                                        'type' => kartik\datetime\DateTimePicker::TYPE_COMPONENT_PREPEND,

                                        'pluginOptions' =>

                                        [

                                            'autoclose' => true,

                                            'format' => 'yyyy-m-dd HH:ii P'

                                        ],

                                        'options' => [

                                            'placeholder' => Yii::t('app', 'Bitte defnieren Sie einen Zeitpunkt'),]

                                    ]);

                                    ?>   



Well, to be honest, I’m afraid that removing “id” field from the form would not solve the problem.

As I remember, you are using some extension that enables you to save a model with its relational model(s) in one shot. I mean the extension that supports “saveAll()”. And I think an incorrect usage of the extension might be the cause of your problem. Or, some extension that supports blamable behavior could be the cause. I’m not sure. You are trying to use too many seemingly fancy extensions.

It may be controversial, but I believe that we should not use any third-party extension until we’ve reached a point where we definitely need it, especially while we are not very familiar with the basics of the framework core.

What do you mean with ([color=#1C2837][size=2]seemingly fancy) [/size][/color]extensions? Which code should I paste to show U up these extensions,in order to remove them

I dont’ use saveAll() any more, as U adviced me not to use it

As I noticed,in my other projects, I don’t have this problem. But here,handling multi models,I got it.

Here again Controller code:





   public function actionCreate() {

        //try {


        $model = new Bewerber(['scenario' => Bewerber::SCENARIO_CREATE]);

        $model_person = new Person(['scenario' => Person::SCENARIO_CREATE]);

        $behavior = new \common\wsl_components\Wsl_Blameable_Behavior();

        $angelegt_von = $behavior->get_User_Person_Id();

        if (!$model || !$model_person) {

            throw new NotFoundHttpException("Bitte überprüfen Sie die Validität der Tabellen bewerber bzw. person");

        }

        $model->angelegt_von = $angelegt_von;

        $model_person->angelegt_von = $angelegt_von;

        if ($model->load(Yii::$app->request->post()) && $model_person->load(Yii::$app->request->post())) {

            $valid = $model->validate();

            $isValid = $model_person->validate();

            $isValid = $valid & $isValid;

            if ($isValid) {

                $model->avatar = UploadedFile::getInstances($model, 'avatar');

                $model->upload();

                $model_person->save();

                $model->save();

                return $this->redirect(['view', 'id' => $model->id]);

            } else {

                $error_person = $model_person->getErrors();

                $error_bewerber = $model->getErrors();

                foreach ($error_person as $values) {

                    foreach ($values as $ausgabe) {

                        echo"<p>" . $ausgabe . "</p>";

                    }

                }

                foreach ($error_bewerber as $values) {

                    foreach ($values as $ausgabe) {

                        echo"<p>" . $ausgabe . "</p>";

                    }

                }

                echo Growl::widget([

                    'type' => Growl::TYPE_DANGER,

                    'title' => 'Oh snap!',

                    'icon' => 'glyphicon glyphicon-remove-sign',

                    'body' => 'Aus unbekannten Gründen konnten die Tabellen nicht validiert werden<br>Bitte informieren Sie den Hersteller gemäß obiger Angaben!',

                    'showSeparator' => true,

                    'delay' => 2000,

                    'pluginOptions' => [

                        'showProgressbar' => true,

                        'placement' => [

                            'from' => 'top',

                            'align' => 'center',

                        ]

                    ]

                ]);

                return $this->render('create', [

                            'model' => $model,

                            'model_person' => $model_person,

                ]);

            }

        } else {

            return $this->render('create', [

                        'model' => $model,

                        'model_person' => $model_person,

            ]);

        }

        /* } catch (\Exception $error) {

          $go_back = "bewerber";

          \common\wsl_components\error_handling::error($error, $go_back);

          } */

    }



I had a feeling I’d read this long ago. Looked it up now.

https://dev.mysql.com/doc/refman/5.7/en/example-auto-increment.html

I think the problems could be hidden in your model code, or in the way that you are trying to use extensions, Probably you are saving the same model twice.

But, well, I don’t want to read too much of your code. Please debug your code for yourself.

If you are not using xdebug’s code tracing for debugging, use it. It should be able to integrate it in your IDE.

I debugged ,as U suggested me and changed code like this:





.

.

.   	

 	$model_person_ = Person::find();

        $id_max_person = $model_person_->select('id')->max('id');

        $id_max_person++;

.

.

.


   	$model_person->id = $id_max_person;

                var_dump($model_person->id);

                die();

                $model_person->save();

                var_dump($model_person->id);

                die();



I noticed,that first var_dump will show up int 8, as it should be,'cause seven records are in table. But second var_dump will show up following:[size=“2”]int(9661)[/size]

[size="2"]Now, I am totally confused. How can this be??[/size]

[size="2"]If I repeat script pushing repeat circle in browser, next record will have id 9662,then 9663 etc…

[/size][size="2"]Why will change method save() primary key id,jumping from 7 to 9661?[/size]