gpt4 book ai didi

node.js - 无法生成迁移

转载 作者:行者123 更新时间:2023-11-29 13:08:49 24 4
gpt4 key购买 nike

我有一个项目使用 typeorm 创建数据库。当我执行命令生成到我的项目的迁移时,它给了我错误

我有以下 orm 配置 json 文件:

 {
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "postgres",
"password": "",
"database": "postgres",
"synchronize": true,
"logging": false,
"entities": [
"src/entity/**/*.ts"
],
"migrations": [
"src/migration/**/*.ts"
],
"subscribers": [
"src/subscriber/**/*.ts"
],
"cli": {
"entitiesDir": "src/entity",
"migrationsDir": "src/migration",
"subscribersDir": "src/subscriber"
}
}

我有这个用户实体类:

import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from "typeorm";
import { Transaction } from "./Transactions";
export type UserStatus = "Active" | "Inactive";

@Entity()
export class User {

@PrimaryGeneratedColumn()
id: number;

@Column("varchar",{
length:50
})
account_id: string;

@Column("varchar",{
length: 50
})
name: string;

@Column("varchar",{
length:50
})
email: string;

@Column("varchar",{
length:15
})
phone_number: string;

@Column("varchar",{
length:50
})
address: string;

@Column({
type: "enum",
enum: ["Active", "Inactive"]
}) status: UserStatus;


@Column("varchar",{
length:50
})
current_id: string;

@OneToMany(type => Transaction, transaction => transaction.user)
transactions: Transaction[];

}

如果我执行生成迁移的命令,它会给我以下错误:

C:\Users\Firdaus97\source\repos\Cust Local payment\Cust Local payment\MyProject>ts-node ./node_modules/.bin/typeorm migrations:generate -n
C:\Users\Firdaus97\source\repos\Cust Local payment\Cust Local payment\MyProject\node_modules\.bin\typeorm:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^

SyntaxError: missing ) after argument list
at Module._compile (internal/modules/cjs/loader.js:720:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:788:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:840:10)
at Object.<anonymous> (C:\Users\Firdaus97\AppData\Roaming\npm\node_modules\ts-node\src\bin.ts:158:12)
at Module._compile (internal/modules/cjs/loader.js:777:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:788:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)

最佳答案

我在 Windows 10 上遇到了这个问题,并且能够根据 this answer 修复它和 this comment :

在我的 package.json我之前的脚本

  "scripts": {
...
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/.bin/typeorm",
"migration:generate": "npm run typeorm migration:generate -- -n",
}

我换了“typeorm”与

  "scripts": {
...
"typeorm:win": "ts-node -r tsconfig-paths/register node_modules\\typeorm\\cli.js",
"migration:generate:win": "npm run typeorm:win migration:generate -- -n"
}

然后这就像一个魅力 npm run migration:generate:win -n <<migration name>>

关于node.js - 无法生成迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57601796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com