0
votes

Good day, tried to install this extension https://github.com/cinghie/yii2-articles

I get such an error, how can I fix it?

yii\base\UnknownPropertyException: Setting unknown property: cinghie\articles\Articles::0 in** /var/www/html/basic/vendor/yiisoft/yii2/base/Component.php:209
Stack trace:
#0 /var/www/html/basic/vendor/yiisoft/yii2/BaseYii.php(546): yii\base\Component->__set('0', Array)
#1 /var/www/html/basic/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\BaseYii::configure(Object(cinghie\articles\Articles), Array)
#2 /var/www/html/basic/vendor/yiisoft/yii2/base/Module.php(158): yii\base\BaseObject->__construct(Array)
#3 [internal function]: yii\base\Module->__construct('articles', Object(yii\web\Application), Array)
#4 /var/www/html/basic/vendor/yiisoft/yii2/di/Container.php(384): ReflectionClass->newInstanceArgs(Array)
#5 /var/www/html/basic/vendor/yiisoft/yii2/di/Container.php(156): yii\di\Container->build('cinghie\\article...', Array, Array)
#6 /var/www/html/basic/vendor/yiisoft/yii2/BaseYii.php(349): yii\di\Container->get('cinghie\\article...', Array, Array)
#7 /var/www/html/basic/vendor/yiisoft/yii2/base/Module.php(427): yii\BaseYii::createObject(Array, Array)
#8 /var/www/html/basic/vendor/yiisoft/yii2/base/Module.php(586): yii\base\Module->getModule('articles')
#9 /var/www/html/basic/vendor/yiisoft/yii2/base/Module.php(522): yii\base\Module->createController('categories')
#10 /var/www/html/basic/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('articles/catego...', Array)
#11 /var/www/html/basic/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#12 /var/www/html/basic/web/index.php(12): yii\base\Application->run()
#13 {main}

Perhaps the reason is that according to the instructions, you need to override PREFIX_ with a table prefix. I did it like this:

SQL query:

INSERT INTO `auth_assignment` (` item_name`, `user_id`,` created_at`) VALUES
('admin', '1', 1451514052);

after the SQL query produces the following

MySQL response:

#1452 - Cannot add or update a child row: a foreign key constraint fails (ubuntu.auth_assignment, CONSTRAINT auth_assignment_ibfk_1 FOREIGN KEY (item_name) REFERENCES auth_item (name) ON DELETE CASCADE ON UPDATE CASCADE)

Update

The SQL query was executed, the admin id = 1 entry was added, but the error remains the same:

Setting unknown property: cinghie \ Articles \ Articles :: 0

Maybe because 3 migrations from 7 failed:

output from console

1
I fixed formatting BUT you must ask your question in English. - Bsquare ℬℬ

1 Answers

0
votes

Wha looks like you havent added the admin role before assigning the role to your user, make sure you have the admin role added in your auth_item table as the foreign key constraint error is referring to, there should be an entry like below

+-------+------+-------------+-----------+------+------------+------------+
| name  | type | description | rule_name | data | created_at | updated_at |
+-------+------+-------------+-----------+------+------------+------------+
| admin |    1 | NULL        | NULL      | NULL | 1525039496 | 1525039496 |
+-------+------+-------------+-----------+------+------------+------------+
1 row in set (0.00 sec)

otherwise, run the following query

INSERT INTO `auth_item` (`name`, `type`) VALUES
('admin', 1);

Now run the query that is required by the extension and it will work fine.

INSERT INTO `auth_assignment` (` item_name`, `user_id`,` created_at`) VALUES
('admin', '1', 1451514052);

Update

The migration failed because you don't have a user with id = 1 in the user table, see the error that is being raised for the foreign key.

Exception: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (ubuntu.article_items, CONSTRAINT fk_article_items_user_id FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE SET NULL ON UPDATE CASCADE)

and the sql executed has the id 1 as user_id that is being inserted so you should make sure you have the user with same id