Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Didn't Found Entity Column Error #191

Open
NickClicknClear opened this issue Aug 21, 2019 · 5 comments
Open

Didn't Found Entity Column Error #191

NickClicknClear opened this issue Aug 21, 2019 · 5 comments
Labels
bug no known workaround

Comments

@NickClicknClear
Copy link

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.

[email protected]
[18:20:49] Starting creation of model classes.
Relation between tables User_Role and User didn't found entity column User_Role.undefined.
Error occured in typeorm-model-generator.
[email protected]  [email protected]
If you think this is a bug please open an issue including this log on https://github.com/Kononnable/typeorm-model-generator/issues
Error
    at Object.LogError (/Users/nicklong/.npm/_npx/72072/lib/node_modules/typeorm-model-generator/dist/src/Utils.js:10:21)
 at /Users/nicklong/.npm/_npx/72072/lib/node_modules/typeorm-model-generator/dist/src/drivers/AbstractDriver.js:156:31
    at Array.forEach (<anonymous>)

I think it's expecting some kind of naming convention, but I'm not sure what's expected?

@Kononnable
Copy link
Owner

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.

@NickClicknClear
Copy link
Author

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.

@Kononnable
Copy link
Owner

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 [email protected] -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?

@NickClicknClear
Copy link
Author

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.

@Kononnable
Copy link
Owner

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.

@Kononnable Kononnable added the bug no known workaround label Sep 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug no known workaround
Projects
None yet
Development

No branches or pull requests

2 participants