question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Schema generation fails silently when @PrimaryColumn is ommitted

See original GitHub issue

I have the following working entity:

export class AddressDbSchema implements AddressDTO {
    @PrimaryColumn()
    public _id?: string;
    @Column()
    public address1: string;
    @Column()
    public address2?: string;
    @Column()
    public city: string;
    @Column()
    public state: string;
    @Column()
    public zip: string;
    @Column()
    public country: string;
}

Here’s the calling code:

export class AddressRepositoryImplDb implements AddressRepository {
    private addressRepository: Repository<AddressDbSchema>;

    constructor() {
        this.connect().then(async connection => {
            this.addressRepository = connection.getRepository(AddressDbSchema);
        });
    }

    public async findAll(): Promise<Array<AddressDTO>> {
        return await this.addressRepository.find();
    }

    public async create(addressDTO: AddressDTO): Promise<AddressDTO> {
        return await this.addressRepository.persist(addressDTO);
    }

    public async update(addressDTO: AddressDTO): Promise<AddressDTO> {
        return await this.addressRepository.persist(addressDTO);
    }

    public async find(id: string): Promise<AddressDTO> {
        return await this.addressRepository.findOneById(id);
    }

    private connect(): Promise<Connection> {
        return createConnection({
            driver: {
                type: 'sqlite',
                storage: 'tmp/sqlitedb.db'
            },
            logging: {
                logQueries: true,
                logSchemaCreation: true
            },
            autoSchemaSync: true,
            entities: [
                AddressDbSchema
            ]
        });
    }
}

If I modify the entity to look like this, schema generation fails, but I get no error messages.

export class AddressDbSchema implements AddressDTO {
    @Column()
    public _id?: string;
    @Column()
    public address1: string;
    @Column()
    public address2?: string;
    @Column()
    public city: string;
    @Column()
    public state: string;
    @Column()
    public zip: string;
    @Column()
    public country: string;
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
timwhitcommented, Oct 31, 2016

Thanks.

I updated the connection code and I’m getting the error now.

        this.connect().then(async connection => {
            this.addressRepository = connection.getRepository(AddressDbSchema);
        }).catch(err => logger.error('Cannot connect to database', err));

I would request that the examples on the README include this as I basically just copied the examples and none of them include catch.

0reactions
timwhitcommented, Nov 26, 2016

Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

typeorm/typeorm - Gitter
Hi! I'm having a hard time setting the current timestamp to a column on an MySQL database. My entity is the following: @Column({...
Read more >
15.10 - TPT4130 Error: Schema generation failed for SELECT ...
TPT4130 Error: Schema generation failed for SELECT statement '%s' in DBS '%s': GetSelectStmtSchema status: %d.
Read more >
SQL Developer Dialog Boxes and Wizards - Oracle Help Center
This dialog box is displayed when you specify an invalid file after clicking Add in the XML Schemas pane of SQL Developer preferences....
Read more >
typeorm: CHANGELOG
Primary column name must match the relation name + join column name on related entity. If related entity has multiple primary keys, and...
Read more >
Can a database table not have a primary key?
Actually, SQLite silently creates a primary key column for your called ... it errors out: Parse error: PRIMARY KEY missing on table t1...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found