Theodo-UK / nestjs-admin

A generic administration interface for TypeORM entities
https://nestjs-admin.com
MIT License
536 stars 60 forks source link

Could not connect to your database to create an admin user #162

Open mosilver opened 4 years ago

mosilver commented 4 years ago

According to the documentation I have installed package, added module admin, admin entity, the db migration that added adminuser table and then I try to add the admin user with command:

$npx nestjs-admin createAdminUser

and I get error:

Error: Could not connect to your database to create an admin user. Make sure you have an ormconfig file with a default connection or that your environment variables are set (see https://github.com/typeorm/typeorm/blob/master/docs/using-ormconfig.md). at Function. (C:\api\node_modules\nestjs-admin\bin\cliAdmin.module.ts:18:13) at Generator.throw () at rejected (C:\api\node_modules\nestjs-admin\dist\bin\cliAdmin.module.js:5:65) at processTicksAndRejections (internal/process/task_queues.js:94:5)

but the ormconfig works when I just start the app (after table remove as I get as well issue with: [ExceptionHandler] ER_TABLE_EXISTS_ERROR: Table 'adminuser' already exists +1ms QueryFailedError: ER_TABLE_EXISTS_ERROR: Table 'adminuser' already exists )

my config:

`const AdminUser = require('nestjs-admin').AdminUserEntity;

const config: ConnectionOptions = { type: 'mysql', host: 'localhost', port: 3306, username: 'root', password: '', database: 'suplineo', entities: [dirname + '//.entity{.ts,.js}', IngredientEntity, AdminUser], //entities: ["src//.entity{.ts,.js}"], synchronize: true, migrationsRun: false, logging: true, logger: 'file', migrations: [dirname + '/migrations/*/{.ts,.js}'], cli: { "migrationsDir": "src/migrations" } };`

williamdclt commented 4 years ago

Is it an .ormconfig.ts you pasted? It looks like TypeORM couldn't find it

It's not super clear from the docs, but basically the nestjs-admin command relies on TypeORM being able to discover your configuration automatically. Which means you have 2 options for it to work:

mosilver commented 4 years ago

I had the ormconfig.ts in src folder, so I moved it to the root of project near package.json but the effect is still the same - standard app is starting (left terminal) adding admin fails (right terminal), I attach the full content of config as well:

error localization

https://www.dropbox.com/s/u5kh259y3oa8uy7/localization.jpg?dl=0 https://www.dropbox.com/s/7njy07hvu9ag2w7/error.jpg?dl=0

fadhilx commented 3 years ago

hi i have the same error, i follow the tutorial in https://nestjs-admin.com/docs/install

Unable to connect to the database. Retrying (1)...
QueryFailedError: Table 'adminuser' already exists