i want to do generate for entity which i have created to database using typeorm

but i get an error like this

Generates a new migration file with sql needs to be executed to update schemaNot enough non-option arguments: got 0, need at least 1Note: This command was run via npm module 'win-node-env'npm ERR! code ELIFECYCLEnpm ERR! [email protected] typeorm: NODE_ENV=migration ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js -f --config ./src/config/ormconfig.ts "migration:generate" "--name" "create_table_user"npm ERR! Exit status 1npm ERR!npm ERR! Failed at the [email protected] typeorm script.npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:npm ERR! C:\Users\jojo\AppData\Roaming\npm-cache\logs\2022-11-13T12_28_28_622Z-debug.log

this is my project structureenter image description here

inside my ormconfig.ts file like this

`

import * as dotenv from 'dotenv';import { TypeOrmModuleOptions } from '@nestjs/typeorm';dotenv.config();const dir = process.env.NODE_ENV == 'migration' ? 'src' : 'dist';export default <TypeOrmModuleOptions>{type: process.env.DATABASE_CONNECTION,host: process.env.DATABASE_HOST,port: Number(process.env.DATABASE_PORT),username: process.env.DATABASE_USERNAME,password: process.env.DATABASE_PASSWORD,database: process.env.DATABASE_NAME,entities: [`${dir}/**/*.entity.{js,ts}`],migrations: [`${dir}/models/migrations/*.{js,ts}`],seeds: [`${dir}/models/migrations/seeds/*.seed.{js,ts}`],factories: [`${dir}/models/migrations/seeds/factories/*.factory.{js,ts}`],cli: {migrationsDir: `${dir}/models/migrations`,entitiesDir: `${dir}/models/entities`,seedersDir: `${dir}/models/migrations/seeds`,factoriesDir: `${dir}/models/migrations/seeds/factories`,},synchronize: false,migrationsRun: false,};

`

and the script that I created in the package.json file is like this`

"typeorm": "NODE_ENV=migration ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js -f --config ./src/config/ormconfig.ts","typeorm:migration:generate": "npm run typeorm migration:generate -- --name","typeorm:migration:create": "npm run typeorm migration:create -- --name","typeorm:migration:run": "npm run typeorm migration:run","typeorm:migration:revert": "npm run typeorm migration:revert","typeorm:seed": "NODE_ENV=migration ts-node ./node_modules/typeorm-seeding/dist/cli.js --configName ./src/config/ormconfig.ts","typeorm:seed:run": "npm run typeorm:seed seed","typeorm:schema:drop": "ts-node ./node_modules/typeorm/cli.js schema:drop"

`

but when I try to migrate, I get an error like the one aboveso what should I do to be able to migrate?

1

Best Answer


I think the problem in your command to run migration missing some args.Have you built before running new migration?what is your typeorm version you're using?in my case use 0.2.45:

my package.json script:enter image description here

my command to create new migration base on entity (remember build first):

npm run migration:generate your_migration_name

try it!