Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Some questions #2

Open
webeffected opened this issue Oct 29, 2020 · 3 comments
Open

Some questions #2

webeffected opened this issue Oct 29, 2020 · 3 comments

Comments

@webeffected
Copy link

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?

@thecodeholic
Copy link
Owner

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.

@webeffected
Copy link
Author

webeffected commented Oct 29, 2020

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
Copy link
Author

Solved!

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants