So, I have a:
menu
sections
dishes
the dishes are in a specific section, and the sections are in a certain menu
I use postgresql 9.6 as db
I created the first migration for the menu:
public function safeUp() { $tableOptions = null; if ($this->db->driverName === 'mysql') { // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; } $this->createTable('{{%menu_list}}', [ 'id' => $this->primaryKey(), 'title_ru' => $this->string()->notNull(), 'title_en' => $this->string()->notNull(), 'url' => $this->string(), 'img_url' => $this->string(), 'weight' => $this->integer(), 'status' => $this->smallInteger()->notNull()->defaultValue(1), 'created_at' => $this->integer()->notNull(), 'updated_at' => $this->integer()->notNull(), ], $tableOptions); $this->createIndex('FK_menu', '{{%menu_list}}', 'id'); } public function safeDown() { $this->dropTable('{{%menu_list}}'); } and the second migration for sections and dishes:
public function safeUp() { $tableOptions = null; if ($this->db->driverName === 'mysql') { // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; } $this->createTable('{{%category}}', [ 'id' => $this->primaryKey(), 'title_ru' => $this->string()->notNull(), 'title_en' => $this->string()->notNull(), 'url' => $this->string(), 'img_url' => $this->string(), 'weight' => $this->integer(), 'menu_id' => $this->integer()->notNull(), 'status' => $this->smallInteger()->notNull()->defaultValue(1), 'created_at' => $this->integer()->notNull(), 'updated_at' => $this->timestamp(), ], $tableOptions); $this->createTable('{{%dish}}', [ 'id' => $this->primaryKey(), 'title_ru' => $this->string()->notNull(), 'title_en' => $this->string()->notNull(), 'desc_ru' => $this->string(), 'desc_en' => $this->string(), 'url' => $this->string(), 'img_url' => $this->string(), 'weight' => $this->integer(), 'category_id' => $this->integer()->notNull(), 'status' => $this->smallInteger()->notNull()->defaultValue(1), 'created_at' => $this->integer()->notNull(), 'updated_at' => $this->integer()->notNull(), ], $tableOptions); $this->createIndex('FK_dish_category', '{{%dish}}', 'category_id'); $this->addForeignKey( 'FK_dish_category', '{{%dish}}', 'category_id', '{{%category}}', 'id', 'SET NULL', 'CASCADE' ); $this->createIndex('FK_category_menu', '{{%category}}', 'menu_id'); $this->addForeignKey( 'FK_category_menu', '{{%category}}', 'menu_id', '{{%menu_list}}', 'id', 'SET NULL', 'CASCADE' ); } public function safeDown() { $this->dropTable('{{%dish}}'); $this->dropTable('{{%category}}'); } everything would be fine, but when I try to generate code through the CRUD of the yii2 itself for the model I created for the category table, I simply redirect with an error without any errors
Error (# 1) An internal server error occurred.
( http://joxi.ru/p27oVyRfodp0y2 )
it seems to me that my migration is not written correctly and as a result, a wrong model with incorrect dependencies was created and the code is not generated using CRUD specifically for the category model (for the rest of the models everything was generated normally), please help.
/web/index.phpinstead of the first lines, specify itdefined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev');defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev');After that, on the page, instead ofAn internal server error occurredessence of the error will be described. There we will understand further what the problem is. - Al Mr