Yii2-Youtube-Clone icon indicating copy to clipboard operation
Yii2-Youtube-Clone copied to clipboard

Some questions

Open webeffected opened this issue 5 years ago • 3 comments

Hello Zura!

Thanks a lot for your 7 hour tutorial. It really helps!

However I have some issues with it. If you don't mind I will post my questions here in one place as I go through your video.

And the first one is about Gii. Before it everything was smooth and clear. Time stamp is about here - https://youtu.be/whuIf33v2Ug?t=6658

In your code in rules method you have this line:

[['created_by'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['created_by' => 'id']],

I don't have it, rules end with:

[['video_id'], 'unique'],

attributeLabels() looks fine, just like yours and then my code ends with find() method. I don't have getCreatedBy() method generated.

My first though was about DB, maybe I had some mismatches there, so I've completed migration several times, and followed your gii generation about 3 times, but without any luck, my code is generated differently from yours. I've even copy-pasted your migration code and tried one more time.

My Yii version is 2.0.38, but you've used 2.0.34. Could it be the reason?

webeffected avatar Oct 29 '20 07:10 webeffected

Hello,

I don't think it is a version problem. Do you have created_by column in videos table which has foreign key on users?

It seems to me that this column does not exist or there is no foreign key on users table.

thecodeholic avatar Oct 29 '20 07:10 thecodeholic

Yes, I do. In migrations file I have this code:

			$this->addForeignKey(
				'{{%fk-videos-created_by}}',
				'{{%video}}',
				'created_by',
				'{{%user}}',
				'id',
				'CASCADE'
			);

Last time I even copied your migration code to my project. Nothing changed.

In console after migration:

> add foreign key {{%fk-videos-created_by}}: {{%video}} (created_by) references {{%user}} (id) ... done (time: 0.045s)

webeffected avatar Oct 29 '20 08:10 webeffected

Solved!

Created table was in MyISAM, changed default storage engine in phpmyadmin Variables to InnoDB and now everything works as expected!

webeffected avatar Oct 29 '20 09:10 webeffected