Open NickClicknClear opened 5 years ago
Can you please provide DDL statements for your database? I have to reproduce the issue to know what's going wrong. Tests pass on mariadb, so it looks like it's some specific case.
Thanks for looking into this.
The table I ran the script against looked like this:
# Dump of table Role
# ------------------------------------------------------------
DROP TABLE IF EXISTS `Role`;
CREATE TABLE `Role` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
# Dump of table User
# ------------------------------------------------------------
DROP TABLE IF EXISTS `User`;
CREATE TABLE `User` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
`email` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL,
`password` varchar(255) NOT NULL DEFAULT '',
`isActive` tinyint(1) NOT NULL DEFAULT 1,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
# Dump of table User_Role
# ------------------------------------------------------------
DROP TABLE IF EXISTS `User_Role`;
CREATE TABLE `User_Role` (
`userID` int(11) unsigned NOT NULL,
`roleID` int(11) unsigned NOT NULL,
PRIMARY KEY (`userID`,`roleID`),
KEY `RoleID` (`roleID`),
CONSTRAINT `user_role_ibfk_1` FOREIGN KEY (`UserID`) REFERENCES `User` (`id`),
CONSTRAINT `user_role_ibfk_2` FOREIGN KEY (`roleID`) REFERENCES `Role` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Let me know if you need any further information.
I couldn't reproduce your issue - it generated proper entities for me. I used just simple model generation, without additional flags which might be the reason(npx typeorm-model-generator@v0.3.4 -h localhost -e mariadb -d test -u root -x admin -p 3307
).
Which exactly db version are you using? Are you using any additional flags, or just simple model generation?
I've done a bit more digging and I can reproduce the issue reliably though I'm not really sure why it is happening.
I don't think it's anything to do with my specific schema.
If I create a new database and import the SQL I can run:
npx typeorm-model-generator -h localhost -e mariadb -d test -u root -x password -p 3306
and it works fine.
If I then rename the database to test2 using SequelPro and run
npx typeorm-model-generator -h localhost -e mariadb -d test2 -u root -x password -p 3306
It will then fail with the error: Relation between tables User_Role and user didn't found entity model user.
So I think the issue might be Sequel Pro doing something weird to the database if you rename it although I don't know quite what.
I can now easily work around this issue so I'm happy for you to close, but I thought I'd provide you with the information in case you wanted to look into it further.
Probably renaming database(tool doesn't matter) produces this bug. I will keep this open till I have some more time to fix the issue.
Just testing out this tool with a simple Maria database with User, Role and User_Role tables with a many to many relationship and I got this error.
I think it's expecting some kind of naming convention, but I'm not sure what's expected?