typeorm: TypeError: Cannot read property 'COLLATION' of undefined
Issue type:
[X ] question [ ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[X ] mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[X ] latest
[ ] @next
[ ] 0.x.x (or put your version here)
Getting below error when I tried to insert the second record into a mariadb table.
TypeError: Cannot read property 'COLLATION' of undefined at MysqlQueryRunner.<anonymous> (/Users/z244282/Desktop/MyProject/src/driver/mysql/MysqlQueryRunner.ts:1154:49) at step (/Users/z244282/Desktop/MyProject/node_modules/typeorm/driver/mysql/MysqlQueryRunner.js:42:23) at Object.next (/Users/z244282/Desktop/MyProject/node_modules/typeorm/driver/mysql/MysqlQueryRunner.js:23:53) at /Users/z244282/Desktop/MyProject/node_modules/typeorm/driver/mysql/MysqlQueryRunner.js:17:71 at new Promise (<anonymous>) at __awaiter (/Users/z244282/Desktop/MyProject/node_modules/typeorm/driver/mysql/MysqlQueryRunner.js:13:12) at /Users/z244282/Desktop/MyProject/src/driver/mysql/MysqlQueryRunner.ts:1150:54 at Array.map (<anonymous>) at MysqlQueryRunner.<anonymous> (/Users/z244282/Desktop/MyProject/src/driver/mysql/MysqlQueryRunner.ts:1150:37) at step (/Users/z244282/Desktop/MyProject/node_modules/typeorm/driver/mysql/MysqlQueryRunner.js:42:23)
Steps to reproduce the issue.
-
Creare a sample with command
typeorm init --name MyProject --database mariadb. -
npm start works fine for the first time. got below output.
Inserting a new user into the database... Saved a new user with id: 1 Loading users from the database... Loaded users: [ User { id: 1, firstName: 'Timber', lastName: 'Saw', age: 25 } ] Here you can setup and run express/koa/any other framework.
- npm start again gives the above error.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 21 (3 by maintainers)
In my case, the issue was using capital letters in my database name. E.g.
TypeORMTestDB->typeormtestdb.This works for me too.
@pleerock emmmmmm, I just started learning node, and I met this problem。Interestingly, I found this to be due to the database naming problem. I’m using MySQL. When I first started the service with a lowercase name, the log showed that the table was created successfully and the database was connected successfully, and the service was started normally the second time. But when I use a mixed case name, an error occurs the second time: “Cannot read property ‘COLLATION’ of undefined.” Limited level, can not find the basic reason —来自有道翻译
That’s right, this works for me too. Don’t use capital letters naming your database.
I was running into the same problem, and the
my.cnftrick didn’t seem to work. For me, what did work was ensuring the table’s name was entirely lowercase. Eg:Table->table.The problem still occurs in osx, typeorm, mariadb and lower_case_table_name=1 doesn’t help as that variable is readonly. Has anyone idea how to fix it?