我的迁移文件代码/值如下所示
$model->setAttributes(
[
'id' => '1',
'title' => 'Tag test',
'slug' => 'ssds',
'status' => '1',
'is_archived' => '0',
'description' => 'sdsdfsd asfda s fsd fsadfasfdsaf',
'created_at' => '2017-12-14 00:00:00',
'updated_at' => '2017-12-14 00:00:00',
'created_by' => '2',
'updated_by' => '2',
'identifier' => 'ssds',
],
但是当我在作曲家中运行命令时,它显示错误
例外:SQLSTATE [23000]:完整性约束违规:1048列'created_by'不能为空正在执行的SQL是:INSERT INTO标记(id,title,slug,status,is_archived,description,created_at,updated_at,created_by,updated_by,identifier )VALUES(1,'标签测试','ssds',1,0,'sdsdfsd asfda s fsd fsadfasfdsaf',NOW(),NOW(),NULL,NULL,'ssds')(E:\ xamp-7 \ htdocs中\ 1712SAM \ dev的\厂商\ yiisoft \ yii2 \分贝\ Schema.php:636)
在这种情况下,您将不安全的属性设置为AR模型,并且为了正确的工作,您需要将setAttributes()函数中的第二个参数设置为false。 http://www.yiiframework.com/doc-2.0/yii-base-model.html#setAttributes()-detail