I am getting the error: Integrity constraint violation: 1048 Column ‘id’ cannot be null.
Full application was generated using command:
composer create-project yiisoft/yii2-app-advanced advanced 2.0.3
I just added one table "tproducta" to database, generated model for it in the "backend" folder and run CRUD. CRUD generated controller in "backend\controllers" folder and several *.php files in "views\tproducta" folder including index.php, create.php, update.php, delete.php…
I try to insert row to the table using generated CRUD using url:
"http://localhost/TCyii/advanced/backend/web/index.php?r=tproducta%2Fcreate"
But i am getting error:
"SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘id’ cannot be null
The SQL being executed was: INSERT INTO tproducta
(id
, website
, good_type
, good_kwd1
, good_kwd2
, good_kwd3
, good_title
, good_manufacturer
, good_price
, good_price_cng1
, good_price_cng2
, good_price_cng3
, good_expiration
, good_techdetails
, good_No_stock
, good_NoOrders
) VALUES (NULL, ‘jfhjgk’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, NULL, NULL, NULL, NULL, NULL, ‘’, NULL, NULL)
Error Info: Array
(
[0] => 23000
[1] => 1048
[2] => Column 'id' cannot be null
)
"
If i remove id from the _form.php deleting line:
<?= $form->field($model, ‘id’)->textInput() ?>
I am getting error: "Bad Request (#400), Missing required parameters: id ", although it is not required.
But the table row is created.
Than i try to create the second row in the table, i am getting error:
"SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘0’ for key ‘PRIMARY’
The SQL being executed was: INSERT INTO tproducta
(website
, good_type
, good_kwd1
, good_kwd2
, good_kwd3
, good_title
, good_manufacturer
, good_price
, good_price_cng1
, good_price_cng2
, good_price_cng3
, good_expiration
, good_techdetails
, good_No_stock
, good_NoOrders
) VALUES (’’, ‘’, ‘’, ‘’, ‘’, ‘jkgkj’, ‘’, NULL, NULL, NULL, NULL, NULL, ‘’, NULL, NULL)
Error Info: Array
(
[0] => 23000
[1] => 1062
[2] => Duplicate entry '0' for key 'PRIMARY'
)
"
In Tproducta controller there is the following rule related to id field:
C:\Bitnami\wampstack-5.4.38-0\apache2\htdocs\TCyii\advanced\backend\models\Tproducta.php
public function rules()
{
return [
//[['id'], 'required'],
[['id', 'good_No_stock', 'good_NoOrders'], 'integer'],
How to tell to yii, not insert the primary key, leave this job to database?