0

My migration file code/value like below but

$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',
 ],

but when I run command in composer it shows error

Exception: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'created_by' cannot be null The SQL being executed was: INSERT INTO tag (id, title, slug, status, is_archived, description, created_at, updated_at, created_by, updated_by, identifier) VALUES (1, 'Tag test ', 'ssds', 1, 0, 'sdsdfsd asfda s fsd fsadfasfdsaf', NOW(), NOW(), NULL, NULL, 'ssds') (E:\xamp-7\htdocs\1712SAM\dev\vendor\yiisoft\yii2\db\Schema.php:636)

Virb
  • 1,639
  • 1
  • 16
  • 25
Destroyer.0211
  • 113
  • 1
  • 3
  • 13

1 Answers1

0

As case, you set unsafe attributes to AR model and for correct work you need set second argument in setAttributes() function to false. http://www.yiiframework.com/doc-2.0/yii-base-model.html#setAttributes()-detail

denhasa
  • 24
  • 1