-
-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gii crashes when table has invalid FKs referencing non-existent tables #185
Comments
I noticed that the error occurs if the option 'All relations' or 'All relations with Inverse' are selected. Maybe something wrong with my tables. Will look at it. |
Yes, I have a table which has broken foreign keys (links to non-existing tables). I guess we need some checks in Gii model generator to handle this case. |
Any idea on how to check it? |
I found similar issue #34, it is closed, but my issue is still relevent. It has difference. To reproduce execute the following SQL: SET FOREIGN_KEY_CHECKS = 0;
CREATE TABLE `tour_to_image_links` (
`product_id` INT(10) UNSIGNED NOT NULL,
`image_id` INT(10) UNSIGNED NOT NULL,
`position` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
`type` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`product_id`, `image_id`),
INDEX `FK_tour_to_image_links_image` (`image_id`),
CONSTRAINT `FK_tour_to_image_links_image` FOREIGN KEY (`image_id`) REFERENCES `images` (`id`) ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT `FK_tour_to_image_links_product` FOREIGN KEY (`product_id`) REFERENCES `tours` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;
CREATE TABLE `images` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`file` VARCHAR(1024) NOT NULL,
`url` VARCHAR(1024) NOT NULL,
`title` VARCHAR(255) NULL DEFAULT NULL,
`description` TEXT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`status` TINYINT(3) UNSIGNED NOT NULL,
PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
ROW_FORMAT=COMPACT
AUTO_INCREMENT=22
;
SET FOREIGN_KEY_CHECKS = 1; Then try to generate model for ANY table, not only of that new tables. Error will be thrown. Next - drop the valid FK: ALTER TABLE `tour_to_image_links`
DROP FOREIGN KEY `FK_tour_to_image_links_image`; Then NO ERROR thrown on model generation, although the table still has broken FK. This case is handled by that issue (#34). Still don't know why this happening. Gonna check later, maybe give a solution. |
* upstream/master: Remove useless import of `Yii` from CRUD generator search model template Fixes yiisoft#379: Fixed bug in view page where delete button not work well Fixes yiisoft#366: Option to allow standardized class names capitals in model generator Fixes yiisoft#327: Fixed bug in Model generator when $baseClass is an abstract class Fixes yiisoft#366: Better class and file names for uppercase tables Update composer.json (yiisoft#364) Fix codestyle (yiisoft#362) prepare for next release release version 2.0.7 Register CSRF meta-tags dynamically Updated CHANGELOG [ci skip] Fixed rules generation for JSON columns Removed redundant line from license [skip ci] added database version to issue template (yiisoft#352) [skip ci] docs/guide-ja revised [ci skip] (yiisoft#349) Updated issue template [skip ci] Fixes yiisoft#185: Fix bug in Model generators when FKs pointing to non-existing tables Fixes yiisoft#340: Fix bug in CRUD SearchModel generator Require Yii 2.0.14 (yiisoft#339) Conflicts: composer.json
This issue has originally been reported by @tekord at yiisoft/yii2#12358.
Moved here by @SilverFire.
What steps will reproduce the problem?
I have MySQL table:
Then I try to generate model class through Gii generator:
What is the expected result?
Successfully generated model.
What do you get instead?
That happened just after 'Preview' button click.
Here is the screenshot: https://i.gyazo.com/5eff52de9661bcf7659fe1eada2a0f1d.png
Additional info
UPD: I just noticed this happens on any table. Tried to clean vendor folder and run
composer update
, but no effect.The text was updated successfully, but these errors were encountered: