{"action":"created","issue":{"url":"https://api.github.com/repos/craftcms/cms/issues/1657","repository_url":"https://api.github.com/repos/craftcms/cms","labels_url":"https://api.github.com/repos/craftcms/cms/issues/1657/labels{/name}","comments_url":"https://api.github.com/repos/craftcms/cms/issues/1657/comments","events_url":"https://api.github.com/repos/craftcms/cms/issues/1657/events","html_url":"https://github.com/craftcms/cms/issues/1657","id":223580196,"number":1657,"title":"ActiveRecord does not work after plugin install in Craft 3.x beta 12","user":{"login":"khalwat","id":7570798,"avatar_url":"https://avatars1.githubusercontent.com/u/7570798?v=3","gravatar_id":"","url":"https://api.github.com/users/khalwat","html_url":"https://github.com/khalwat","followers_url":"https://api.github.com/users/khalwat/followers","following_url":"https://api.github.com/users/khalwat/following{/other_user}","gists_url":"https://api.github.com/users/khalwat/gists{/gist_id}","starred_url":"https://api.github.com/users/khalwat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/khalwat/subscriptions","organizations_url":"https://api.github.com/users/khalwat/orgs","repos_url":"https://api.github.com/users/khalwat/repos","events_url":"https://api.github.com/users/khalwat/events{/privacy}","received_events_url":"https://api.github.com/users/khalwat/received_events","type":"User","site_admin":false},"labels":[{"id":527359859,"url":"https://api.github.com/repos/craftcms/cms/labels/bug","name":"bug","color":"ee0701","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-04-22T17:38:38Z","updated_at":"2017-04-24T16:57:05Z","closed_at":"2017-04-24T16:43:55Z","body":"I have a super-simple plugin called `TestCase` that has an install migration that creates a database table `{{%testcase_dogfood}}`, and then listens for the `Plugins::EVENT_AFTER_INSTALL_PLUGIN` event to save an db row in this table via ActiveRecord:\r\n\r\n```\r\n    public function init()\r\n    {\r\n        parent::init();\r\n        self::$plugin = $this;\r\n\r\n        Event::on(\r\n            Plugins::className(),\r\n            Plugins::EVENT_AFTER_INSTALL_PLUGIN,\r\n            function (PluginEvent $event) {\r\n                if ($event->plugin === $this) {\r\n                    $dogFoodRecord = new DogFoodRecord([\r\n                    ]);\r\n                    $dogFoodRecord->save();\r\n                }\r\n            }\r\n        );\r\n    }\r\n```\r\n\r\nHowever, this results in:\r\n```\r\nInvalid Configuration – yii\\base\\InvalidConfigException\r\n\r\nThe table does not exist: {{%testcase_dogfood}}\r\n```\r\n\r\nExpected result:\r\n\r\n1. I would be able to use the ActiveRecord tables my Install migration has created.\r\n\r\nTestCase plugin attached:\r\n\r\n[testcase.zip](https://github.com/craftcms/cms/files/949149/testcase.zip)\r\n"},"comment":{"url":"https://api.github.com/repos/craftcms/cms/issues/comments/296742933","html_url":"https://github.com/craftcms/cms/issues/1657#issuecomment-296742933","issue_url":"https://api.github.com/repos/craftcms/cms/issues/1657","id":296742933,"user":{"login":"khalwat","id":7570798,"avatar_url":"https://avatars1.githubusercontent.com/u/7570798?v=3","gravatar_id":"","url":"https://api.github.com/users/khalwat","html_url":"https://github.com/khalwat","followers_url":"https://api.github.com/users/khalwat/followers","following_url":"https://api.github.com/users/khalwat/following{/other_user}","gists_url":"https://api.github.com/users/khalwat/gists{/gist_id}","starred_url":"https://api.github.com/users/khalwat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/khalwat/subscriptions","organizations_url":"https://api.github.com/users/khalwat/orgs","repos_url":"https://api.github.com/users/khalwat/repos","events_url":"https://api.github.com/users/khalwat/events{/privacy}","received_events_url":"https://api.github.com/users/khalwat/received_events","type":"User","site_admin":false},"created_at":"2017-04-24T16:57:05Z","updated_at":"2017-04-24T16:57:05Z","body":"So I added this to my `safeUp()` method in my `Install.php` migraiton, and it all works as expected now:\r\n```\r\n                    Craft::$app->db->schema->refresh();\r\n```\r\n\r\nSomething seems wrong tho, I can't imagine that migrations in general don't clear the schema cache. Could it be something particular in terms of the migrations being attached to components that are dynamically loaded?"}}
{"actor":{"display_login":"khalwat"}}