我需要一些有关迁移的帮助。我正在尝试使用迁移来播种数据库。但我收到错误“QueryFailedError:关系“帐户”不存在”。我认为这只是典型的新手错误。所以请检查我的代码:
帐户.实体.ts
import { BeforeInsert, Column, Entity, OneToMany } from 'typeorm';
import { AbstractEntity } from '../../common/abstract.entity';
import { SourceEntity } from '../source/source.entity';
import { UtilsService } from '../../shared/services/utils.service';
@Entity({ name: 'account' })
export class AccountEntity extends AbstractEntity {
@Column({ unique: true })
username: string;
@Column({ nullable: true })
password: string;
@OneToMany(() => SourceEntity, (source) => source.account, {
cascade: true,
})
sources: SourceEntity[];
@BeforeInsert()
async setPassword() {
this.password = UtilsService.generateHash(this.password);
}
}
Run Code Online (Sandbox Code Playgroud)
种子数据.migration.ts
import { getCustomRepository, MigrationInterface, QueryRunner } from …Run Code Online (Sandbox Code Playgroud) 我正在处理一项看似典型的面试任务 - 通过该数字的指数计算斐波那契数。但是任务的难点是索引可以达到2000000。我遇到了几个问题,我不明白为什么会发生。
先上代码:
function fib(number) {
const left = Math.pow((1 + Math.sqrt(5)) / 2, number);
const right = Math.pow((1 - Math.sqrt(5)) / 2, number);
const result = Math.round((left - right) / Math.sqrt(5));
console.log(result); //
return BigInt(result); //
}
Run Code Online (Sandbox Code Playgroud)
问题:
fib(96);
console.log(result) // -> 51680708854858490000
BigInt(result) // 51680708854858489856
Run Code Online (Sandbox Code Playgroud)
fib(96);
// Must return 51680708854858323072
// But return BigInt 51680708854858489856
Run Code Online (Sandbox Code Playgroud) bigint ×1
database ×1
fibonacci ×1
javascript ×1
nestjs ×1
node.js ×1
postgresql ×1
typeorm ×1